Package org.jboss.util
Class StopWatch
- java.lang.Object
-
- org.jboss.util.StopWatch
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
StopWatch.Wrapper
public class StopWatch extends java.lang.Object implements java.io.Serializable, java.lang.CloneableSimulates a stop watch with a lap counter.- Version:
- $Revision$
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classStopWatch.WrapperBase wrapper class for other wrappers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Return a cloned copy of this object.private voidformatElapsedTime(java.lang.StringBuffer buff, long lapsed)longgetAverageLapTime()Get the average lap time since the watch was started.intgetLapCount()Get the lap count.longgetLapTime()Get the elapsed lap time since the watch was started.longgetTime()Get the elapsed time since the watch was created or last reset.booleanisRunning()Check if the watch is running.static StopWatchmakeSynchronized(StopWatch watch)Return a synchronized stop watch.voidreset()Reset the watch.voidstart()Start the watch.voidstart(boolean reset)Start the watch.longstop()Stop the watch.java.lang.StringtoString()Return a string representation.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
The serialVersionUID- See Also:
- Constant Field Values
-
total
protected long total
Total time
-
start
protected long start
Start time
-
stop
protected long stop
Stop time
-
count
protected int count
The lap count
-
running
protected boolean running
Is the watch started
-
-
Method Detail
-
start
public void start(boolean reset)
Start the watch.- Parameters:
reset- True to reset the watch prior to starting.
-
start
public void start()
Start the watch.
-
stop
public long stop()
Stop the watch.- Returns:
- Elapsed time or 0 if the watch was never started.
-
reset
public void reset()
Reset the watch.
-
getLapCount
public int getLapCount()
Get the lap count.- Returns:
- The lap count.
-
getLapTime
public long getLapTime()
Get the elapsed lap time since the watch was started.- Returns:
- Elapsed lap time or 0 if the watch was never started
-
getAverageLapTime
public long getAverageLapTime()
Get the average lap time since the watch was started.- Returns:
- Average lap time since the watch was started.
-
getTime
public long getTime()
Get the elapsed time since the watch was created or last reset.- Returns:
- Elapsed time or 0 if the watch was never started.
-
isRunning
public boolean isRunning()
Check if the watch is running.- Returns:
- True if the watch is running.
-
toString
public java.lang.String toString()
Return a string representation.- Overrides:
toStringin classjava.lang.Object
-
formatElapsedTime
private void formatElapsedTime(java.lang.StringBuffer buff, long lapsed)
-
clone
public java.lang.Object clone()
Return a cloned copy of this object.- Overrides:
clonein classjava.lang.Object- Returns:
- A cloned copy of this object.
-
-