net.shibboleth.utilities.java.support.chrono
Class Stopwatch

java.lang.Object
  extended by net.shibboleth.utilities.java.support.chrono.Stopwatch

@NotThreadSafe
public class Stopwatch
extends Object

A stopwatch with millisecond precision.


Field Summary
private  long elapsedTime
          Time that elapsed while the stopwatch was running.
private  Long startTime
          Time the stopwatch was started.
private  Long stopTime
          Time the stopwatch was stopped.
 
Constructor Summary
Stopwatch()
          Constructor.
Stopwatch(long startTimeInMillis)
          Constructor.
 
Method Summary
 long elapsedTime()
          Time, in milliseconds, that elapsed while the stopwatch was running.
 long elapsedTime(TimeUnit unit)
          Time, in the given time unit, that elapsed while the stopwatch was running.
 boolean isRunning()
          Checks if the stopwatch is currently running.
 void reset()
          Reset the stopwatch such that it is not running and no time has elapsed.
 void start()
          Starts the stopwatch if it hasn't been started since being constructed or reset() was called.
 void stop()
          Stops the stopwatch if it hasn't been stopped since being constructed or reset() was called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startTime

private Long startTime
Time the stopwatch was started.


stopTime

private Long stopTime
Time the stopwatch was stopped.


elapsedTime

private long elapsedTime
Time that elapsed while the stopwatch was running.

Constructor Detail

Stopwatch

public Stopwatch()
Constructor.


Stopwatch

public Stopwatch(long startTimeInMillis)
Constructor. Using this constructor creates an already started stopwatch

Parameters:
startTimeInMillis - the time, in milliseconds since the epoch, when the stop watch started
Method Detail

elapsedTime

public long elapsedTime()
Time, in milliseconds, that elapsed while the stopwatch was running.

Returns:
time that elapsed while the stopwatch was running, 0 if the stopwatch has not yet been stopped

elapsedTime

public long elapsedTime(@Nonnull
                        TimeUnit unit)
Time, in the given time unit, that elapsed while the stopwatch was running. Fractions of the given time unit are discarded.

Parameters:
unit - time unit in which the result is returned
Returns:
time that elapsed while the stopwatch was running, 0 if the stopwatch has not yet been stopped

isRunning

public boolean isRunning()
Checks if the stopwatch is currently running.

Returns:
true if the stopwatch is running, false if not

reset

public void reset()
Reset the stopwatch such that it is not running and no time has elapsed.


start

public void start()
Starts the stopwatch if it hasn't been started since being constructed or reset() was called.


stop

public void stop()
Stops the stopwatch if it hasn't been stopped since being constructed or reset() was called.



Copyright © 1999-2012. All Rights Reserved.