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.Cloneable
Simulates 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 class
StopWatch.Wrapper
Base wrapper class for other wrappers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Return a cloned copy of this object.private void
formatElapsedTime(java.lang.StringBuffer buff, long lapsed)
long
getAverageLapTime()
Get the average lap time since the watch was started.int
getLapCount()
Get the lap count.long
getLapTime()
Get the elapsed lap time since the watch was started.long
getTime()
Get the elapsed time since the watch was created or last reset.boolean
isRunning()
Check if the watch is running.static StopWatch
makeSynchronized(StopWatch watch)
Return a synchronized stop watch.void
reset()
Reset the watch.void
start()
Start the watch.void
start(boolean reset)
Start the watch.long
stop()
Stop the watch.java.lang.String
toString()
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:
toString
in 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:
clone
in classjava.lang.Object
- Returns:
- A cloned copy of this object.
-
-