ERXStopWatch Class Reference

Collaboration diagram for ERXStopWatch:

Collaboration graph
[legend]

List of all members.

Public Member Functions

ERXTimeDurationFormatter durationFormat ()
 ERXStopWatch ()
long getNanoTime ()
long getSplitNanoTime ()
long getSplitTime ()
long getStartTime ()
long getTime ()
void reset ()
void resume ()
void split ()
void start ()
void stop ()
void suspend ()
String toSplitString ()
String toString ()
void unsplit ()

Private Attributes

ERXTimeDurationFormatter _durationFormat
final NumberFormat durationFormat = new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.SECOND)
int runningState = STATE_UNSTARTED
int splitState = STATE_UNSPLIT
long startTime
long startTimeMillis
long stopTime

Static Private Attributes

static final long NANO_2_MILLIS = 1000000L
static final int STATE_RUNNING = 1
static final int STATE_SPLIT = 11
static final int STATE_STOPPED = 2
static final int STATE_SUSPENDED = 3
static final int STATE_UNSPLIT = 10
static final int STATE_UNSTARTED = 0


Detailed Description

StopWatch provides a convenient API for timings.

To start the watch, call start(). At this point you can:

It is intended that the output methods toString() and getTime() should only be called after stop, split or suspend, however a suitable result will be returned at other points.

NOTE: As from v2.1, the methods protect against inappropriate calls. Thus you cannot now call stop before start, resume before suspend or unsplit before split.

1. split(), suspend(), or stop() cannot be invoked twice
2. unsplit() may only be called if the watch has been split()
3. resume() may only be called if the watch has been suspend()
4. start() cannot be called twice without calling reset()

This class is not thread-safe

Author:
Apache Software Foundation

kieran (Sep 1, 2010) - borrowed apache lang StopWatch for ERExtensions and changed to our own time duration formatter to eliminate other commons lang dependencies

Since:
2.0
Version:
Id
StopWatch.java 959577 2010-07-01 09:48:23Z sebb

Constructor & Destructor Documentation

ERXStopWatch (  ) 

Constructor.


Member Function Documentation

Returns:
the formatter for the elapsed time

long getNanoTime (  ) 

Get the time on the stopwatch in nanoseconds.

This is either the time between the start and the moment this method is called, or the amount of time between start and stop.

Returns:
the time in nanoseconds
Since:
3.0

long getSplitNanoTime (  ) 

Get the split time on the stopwatch in nanoseconds.

This is the time between start and latest split.

Returns:
the split time in nanoseconds
Exceptions:
IllegalStateException if the StopWatch has not yet been split.
Since:
3.0

long getSplitTime (  ) 

Get the split time on the stopwatch.

This is the time between start and latest split.

Returns:
the split time in milliseconds
Exceptions:
IllegalStateException if the StopWatch has not yet been split.
Since:
2.1

long getStartTime (  ) 

Returns the time this stopwatch was started.

Returns:
the time this stopwatch was started
Exceptions:
IllegalStateException if this StopWatch has not been started
Since:
2.4

long getTime (  ) 

Get the time on the stopwatch.

This is either the time between the start and the moment this method is called, or the amount of time between start and stop.

Returns:
the time in milliseconds

void reset (  ) 

Resets the stopwatch. Stops it if need be.

This method clears the internal values to allow the object to be reused.

void resume (  ) 

Resume the stopwatch after a suspend.

This method resumes the watch after it was suspended. The watch will not include time between the suspend and resume calls in the total time.

Exceptions:
IllegalStateException if the StopWatch has not been suspended.

void split (  ) 

Split the time.

This method sets the stop time of the watch to allow a time to be extracted. The start time is unaffected, enabling unsplit() to continue the timing from the original start point.

Exceptions:
IllegalStateException if the StopWatch is not running.

void start (  ) 

Start the stopwatch.

This method starts a new timing session, clearing any previous values.

Exceptions:
IllegalStateException if the StopWatch is already running.

void stop (  ) 

Stop the stopwatch.

This method ends a new timing session, allowing the time to be retrieved.

Exceptions:
IllegalStateException if the StopWatch is not running.

void suspend (  ) 

Suspend the stopwatch for later resumption.

This method suspends the watch until it is resumed. The watch will not include time between the suspend and resume calls in the total time.

Exceptions:
IllegalStateException if the StopWatch is not currently running.

String toSplitString (  ) 

Gets a summary of the split time that the stopwatch recorded as a string.

The format used is ISO8601-like, hours:minutes:seconds.milliseconds.

Returns:
the split time as a String
Since:
2.1

String toString (  ) 

Gets a summary of the time that the stopwatch recorded as a string.

The format used is ISO8601-like, hours:minutes:seconds.milliseconds.

Returns:
the time as a String Our modified implementation since apache commons lang jar not allowed in ERJars.
See also:
java.lang.Object.toString()

void unsplit (  ) 

Remove a split.

This method clears the stop time. The start time is unaffected, enabling timing from the original start point to continue.

Exceptions:
IllegalStateException if the StopWatch has not been split.


Member Data Documentation

final long NANO_2_MILLIS = 1000000L [static, private]

int runningState = STATE_UNSTARTED [private]

The current running state of the StopWatch.

int splitState = STATE_UNSPLIT [private]

Whether the stopwatch has a split time recorded.

long startTime [private]

The start time.

long startTimeMillis [private]

The start time in Millis - nanoTime is only for elapsed time so we need to also store the currentTimeMillis to maintain the old getStartTime API.

final int STATE_RUNNING = 1 [static, private]

final int STATE_SPLIT = 11 [static, private]

final int STATE_STOPPED = 2 [static, private]

final int STATE_SUSPENDED = 3 [static, private]

final int STATE_UNSPLIT = 10 [static, private]

final int STATE_UNSTARTED = 0 [static, private]

long stopTime [private]

The stop time.


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:15 2012 for Project Wonder by  doxygen 1.5.8