public class ERXStopWatch extends Object
StopWatch
provides a convenient API for timings.
To start the watch, call start()
. At this point you can:
split()
the watch to get the time whilst the watch continues in the background. unsplit()
will
remove the effect of the split. At this point, these three options are available again.suspend()
the watch to pause it. resume()
allows the watch to continue. Any time between the
suspend and resume will not be counted in the total. At this point, these three options are available again.stop()
the watch to complete the timing session.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.
Constructor and Description |
---|
ERXStopWatch()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
ERXTimeDurationFormatter |
durationFormat() |
long |
getNanoTime()
Get the time on the stopwatch in nanoseconds.
|
long |
getSplitNanoTime()
Get the split time on the stopwatch in nanoseconds.
|
long |
getSplitTime()
Get the split time on the stopwatch.
|
long |
getStartTime()
Returns the time this stopwatch was started.
|
long |
getTime()
Get the time on the stopwatch.
|
void |
reset()
Resets the stopwatch.
|
void |
resume()
Resume the stopwatch after a suspend.
|
void |
split()
Split the time.
|
void |
start()
Start the stopwatch.
|
void |
stop()
Stop the stopwatch.
|
void |
suspend()
Suspend the stopwatch for later resumption.
|
String |
toSplitString() |
String |
toString()
Our modified implementation since apache commons lang jar not allowed in ERJars.
|
void |
unsplit()
Remove a split.
|
public void start()
Start the stopwatch.
This method starts a new timing session, clearing any previous values.
IllegalStateException
- if the StopWatch is already running.public void stop()
Stop the stopwatch.
This method ends a new timing session, allowing the time to be retrieved.
IllegalStateException
- if the StopWatch is not running.public void reset()
Resets the stopwatch. Stops it if need be.
This method clears the internal values to allow the object to be reused.
public 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.
IllegalStateException
- if the StopWatch is not running.public 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.
IllegalStateException
- if the StopWatch has not been split.public 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.
IllegalStateException
- if the StopWatch is not currently running.public 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.
IllegalStateException
- if the StopWatch has not been suspended.public 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.
public 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.
public long getSplitTime()
Get the split time on the stopwatch.
This is the time between start and latest split.
IllegalStateException
- if the StopWatch has not yet been split.public long getSplitNanoTime()
Get the split time on the stopwatch in nanoseconds.
This is the time between start and latest split.
IllegalStateException
- if the StopWatch has not yet been split.public long getStartTime()
IllegalStateException
- if this StopWatch has not been startedpublic String toString()
toString
in class Object
Object.toString()
public String toSplitString()
public ERXTimeDurationFormatter durationFormat()
Copyright © 2002 – 2020 Project Wonder.