Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009-2010 Alexander Kerner. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package net.sf.kerner.utils.time;
 

A TimePeriod represents a period of time, which has a start point, a stop point and a duration.

This class is fully thread save.

TODO example

Author(s):
Alexander Kerner
Version:
2010-10-01
See also:
java.util.concurrent.TimeUnit
 
 public class TimePeriod {
 
     // Field //
 
    
Default time unit for this time period.
 
     public final static TimeUnit DEFAULT_TIME_UNIT = .;
     private volatile long startstop;
     private final TimeUnit timeUnit;
 
     // Constructor //
 
    

Constructs a new TimePeriod with given start point, stop point and time unit.

Parameters:
start start point of this TimePeriod
stop stop point of this TimePeriod
timeUnit time unit of start and stop points
See also:
java.util.concurrent.TimeUnit
 
     public TimePeriod(long startlong stopTimeUnit timeUnit) {
         this. = start;
         this. = stop;
         this. = timeUnit;
     }

    

Constructs a new TimePeriod with given start point and stop point.

Parameters:
start start point of this TimePeriod
stop stop point of this TimePeriod
 
     public TimePeriod(long startlong stop) {
         this. = start;
         this. = stop;
         this. = ;
     }
 
     // Private //
 
     // Protected //
 
     // Public //
 
     // Override //
 
     @Override
     public String toString() {
         return Long.toString(getDuration());
     }

    

Returns the start point of this time period. Time unit is DEFAULT_TIME_UNIT.

Returns:
start point of this time period
    public long getStart() {
        return getStart();
    }

    

Returns the stop point of this time period. Time unit is DEFAULT_TIME_UNIT.

Returns:
stop point of this time period
    public long getStop() {
        return getStop();
    }

    

Returns the start point of this time period in given time period.

Parameters:
tu java.util.concurrent.TimeUnit for start point
Returns:
start point of this time period
    public long getStart(TimeUnit tu) {
        return tu.convert();
    }

    

Returns the stop point of this time period in given time period.

Parameters:
tu java.util.concurrent.TimeUnit for stop point
Returns:
stop point of this time period
    public long getStop(TimeUnit tu) {
        return tu.convert();
    }

    

Get duration of this TimePeriod.

Returns:
duration of this time period. Meaning stop point - start point
    public long getDuration() {
        return getDuration();
    }

    

Get duration of this TimePeriod, converted to given TimeUnit.

Parameters:
tu java.util.concurrent.TimeUnit in which duration is measured
Returns:
duration of this time period. Meaning stop point - start point.
    public long getDuration(TimeUnit tu) {
        return tu.convert(( - ), );
    }
New to GrepCode? Check out our FAQ X