public class StopWatchSimple extends Object implements IStopWatch
Modifier and Type | Field and Description |
---|---|
protected long |
allms |
protected long |
m_start |
protected boolean |
running |
Constructor and Description |
---|
StopWatchSimple()
Creates new StopWatchSimple.
|
StopWatchSimple(boolean start)
Creates new StopWatchSimple.
|
Modifier and Type | Method and Description |
---|---|
static void |
main(String[] args)
Test main hook.
|
void |
reset()
This method may serve two purposes:
Running- Reset: The m_start- value of the measurement is set to the current time, even if the StopWatch is running. Next- measurement- Reset: A flag is set which causes the next call to m_start to delete the old m_start - value. Note that continuous calls to m_start() and
stop() without calling reset will always relate the
measurement of time to the first time m_start() was called! |
long |
snapShot()
This method does not change the state from running to !running but performs
an update of the overall measurement- data inside and returns the current
measured time.
|
boolean |
start()
Sets the state to running.
|
boolean |
stop()
Stops the measurement by assigning current time in ms to the stop value.
|
String |
toString()
Returns a String representation of the current measured time in the format
"
|
protected long m_start
protected long allms
protected boolean running
public StopWatchSimple()
public StopWatchSimple(boolean start)
start
- if true time measurement will start just before this call is
returned.public final void reset()
m_start()
and
stop()
without calling reset will always relate the
measurement of time to the first time m_start()
was called!reset
in interface IStopWatch
public final boolean start()
stop()
to
make a new measurement by taking the current time. If reset()
was invoked before, the m_start - time is set to the return value of
System.currentTimeMillis()
. Else the old value is preserved.
False is returned if a measurement is already in progress. A call to
m_start will only m_start a new measurement with the current Time, if it is
the first run or reset was called before. Else the time kept after the next
call to stop will be the sum of all previous runtimes.start
in interface IStopWatch
public long snapShot()
The difference to stop()
:
After
has been called the state is set to
!running which causes a new m_start-value to be set during the next call to
stop()
. The call to
start()
does not switch the state. If afterwards
snapShot()
m_start()
is called, no new value gets assigned to the
m_start- value of the StopWatch. Despite of this
Adds the period from the m_start-value to
now to the internal total measurement- call. To avoid double - summation of
the same time- periods a new start- value is set directly.
snapShot()
snapShot
in interface IStopWatch
IStopWatch.reset()
.stop()
public boolean stop()
stop
in interface IStopWatch
public String toString()
This will take a snapShot()
public static void main(String[] args)
args
- the command line arguments.Copyright © 2019. All rights reserved.