public class JStopWatch
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.List<long[]> |
laps
List of all laps.
|
protected java.lang.String |
name
Optional stopwatch name.
|
protected boolean |
running
Running flag.
|
protected long |
spanTime
Last elapsed time.
|
protected long |
startTime
Last start time.
|
protected long |
stopTime
Last stop time.
|
protected long |
totalTime
Cumulative elapsed time.
|
Constructor and Description |
---|
JStopWatch()
Starts the stopwatch.
|
JStopWatch(java.lang.String name)
Starts the named stopwatch.
|
Modifier and Type | Method and Description |
---|---|
long |
elapsed()
Returns total elapsed time from the
start() in ms. |
static java.lang.String |
formatTimeSpan(long millis)
Formats time spans.
|
long[] |
getLapTimes(int index)
Returns lap times for 1-based lap index.
|
java.lang.String |
getName()
Returns stopwatch name.
|
boolean |
isRunning()
Returns
true if stopwatch is running. |
long |
lap()
Marks a lap and returns its length.
|
protected long |
lap(long lap) |
long |
restart()
Restarts the stopwatch.
|
long |
span()
Stops the stopwatch and returns total time span for last
start-stop sequence.
|
long |
start()
Starts the stopwatch.
|
long |
stop()
Stops the stopwatch if running.
|
java.lang.String |
toString()
Returns total elapsed time as formatted string from the last start.
|
long |
total()
Stops the stopwatch and returns total cumulative time in ms.
|
int |
totalLaps()
Returns the total number of laps up to this moment.
|
protected java.lang.String name
protected long startTime
protected long stopTime
protected long spanTime
protected long totalTime
protected boolean running
protected java.util.List<long[]> laps
public JStopWatch()
public JStopWatch(java.lang.String name)
public java.lang.String getName()
public boolean isRunning()
true
if stopwatch is running.public long start()
stop()
must be called prior to restart.
Returns starting time in milliseconds.public long restart()
public long stop()
public long elapsed()
start()
in ms.public long total()
public long span()
public long lap()
protected long lap(long lap)
public int totalLaps()
public long[] getLapTimes(int index)
null
if laps are not used or if index is invalid.public java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String formatTimeSpan(long millis)
Copyright © 2003-2013 Jodd Team