cpdetector.test
Class StopWatchSimple

java.lang.Object
  extended by cpdetector.test.StopWatchSimple
All Implemented Interfaces:
IStopWatch

public class StopWatchSimple
extends Object
implements IStopWatch

A very simple implementation of the IStopWatch that does nothing more than the interface describes. Only the m_start - value, the running - boolean and the summation of runtimes is hold: Little RAM - consumption and little calculations here.

Version:
1.1
Author:
Achim Westermann

Field Summary
protected  long allms
           
protected  long m_start
           
protected  boolean running
           
 
Constructor Summary
StopWatchSimple()
          Creates new StopWatchSimple.
StopWatchSimple(boolean start)
          Creates new StopWatchSimple.
 
Method Summary
 long getPureMilliSeconds()
          Returns the current value of the IStopWatch in ms.
static void main(String[] args)
           
 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.
 long snapShot()
          This method does not change the state from running to !running but performs an update of the overall measurement- data inside.
 boolean start()
          Sets the state to running.
 boolean stop()
          Stops the measurement by assinging current time in ms to the stop value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_start

protected long m_start

allms

protected long allms

running

protected boolean running
Constructor Detail

StopWatchSimple

public StopWatchSimple()
Creates new StopWatchSimple. The measurement of time is not started here.


StopWatchSimple

public StopWatchSimple(boolean start)
Creates new StopWatchSimple. The measurement of time is started if param is true.

Method Detail

reset

public final void reset()
This method may serve two purposes:
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!

Specified by:
reset in interface IStopWatch

start

public final boolean start()
Sets the state to running. This allows a call to 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.

Specified by:
start in interface IStopWatch

snapShot

public long snapShot()
This method does not change the state from running to !running but performs an update of the overall measurement- data inside. The difference to stop():
After stop() has been called the state is set to !running which causes a new m_start-value to be set during the next call to m_start(). The call to snapShot() does not switch the state. If afterwards m_start() is called, no new value gets assigned to the m_start- value of the StopWatch. Despite of this snapShot 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 m_start- value is set directly.

Specified by:
snapShot in interface IStopWatch

stop

public boolean stop()
Stops the measurement by assinging current time in ms to the stop value. Return true if a valid measurement has been made (StopWatch was running before invoking this method).

Specified by:
stop in interface IStopWatch

getPureMilliSeconds

public final long getPureMilliSeconds()
Returns the current value of the IStopWatch in ms. This has to be the sum of all previous measurements (circles of m_start()-stop()) not interrupted by calls to reset().

Specified by:
getPureMilliSeconds in interface IStopWatch

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] args)


Copyleft ㊢ 2003-2004 MPL 1.1, All Rights Footloose.