com.ds.fw.utils
Class FwTimer

java.lang.Object
  |
  +--com.ds.fw.utils.FwTimer

public class FwTimer
extends java.lang.Object

A simple timer.


Field Summary
 long accumulation
          Contains information how much time(in milliseconds) the timer is running or has run
 java.lang.String name
          The timer name
 long start
          If this variable has value -1 then the timer is stopped, otherwise - the timer is working
 
Constructor Summary
FwTimer()
          The constructor .
FwTimer(java.lang.String s)
          The constructor.
 
Method Summary
 long _getNow()
          Gets the current system time in milliseconds
 double getMilliseconds()
          Returns the time in milliseconds for which the timer has worked or the time since it has been started (in case it is still working)
 java.lang.String getName()
          Gets the name
 double getSeconds()
          Gets the time in seconds for which the timer has worked or the time since it has been started (in case it is still working)
 void initialize()
          Initsialize the fields of this object with default values.
 boolean isRunning()
          Check if the timer is started.
 void reset()
          Reset the value of the timer.
 void setName(java.lang.String s)
          Sets the name
 void start()
          Starts the timer.
static com.ds.fw.utils.FwTimer start(java.lang.String s)
          Starts the timer and sets the timer field name
 void stop()
          Stops the timer.
 java.lang.String toString()
          Returns a string with the name of the timer(if there is any) and the seconds for which the timer has worked or the time (in seconds) since it has been started (in case it is still working).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The timer name


start

public long start
If this variable has value -1 then the timer is stopped, otherwise - the timer is working


accumulation

public long accumulation
Contains information how much time(in milliseconds) the timer is running or has run

Constructor Detail

FwTimer

public FwTimer()
The constructor . Creates a timer object and initsialize it with default values.


FwTimer

public FwTimer(java.lang.String s)
The constructor. Creates a timer object with a given name

Method Detail

start

public static com.ds.fw.utils.FwTimer start(java.lang.String s)
Starts the timer and sets the timer field name

Parameters:
s - the timer name
Returns:

initialize

public void initialize()
Initsialize the fields of this object with default values. Called by the constructor.


start

public void start()
Starts the timer. Checks the fields variable start , if it is different than -1 sets it with the current time in milliseconds


stop

public void stop()
Stops the timer. If the timer is started, stops it and change the value of the field variable accumulation with the time in milliseconds , that the timer has run.


reset

public void reset()
Reset the value of the timer. Sets the value of the variable accumulation to 0. If the timer is running sets the value of the timer to the current time.


getName

public java.lang.String getName()
Gets the name

Returns:
the name

setName

public void setName(java.lang.String s)
Sets the name

Parameters:
s - - the new name

isRunning

public boolean isRunning()
Check if the timer is started.

Returns:
true if the timer is running

getMilliseconds

public double getMilliseconds()
Returns the time in milliseconds for which the timer has worked or the time since it has been started (in case it is still working)

Returns:
the time in milliseconds

getSeconds

public double getSeconds()
Gets the time in seconds for which the timer has worked or the time since it has been started (in case it is still working)

Returns:
the time in seconds

toString

public java.lang.String toString()
Returns a string with the name of the timer(if there is any) and the seconds for which the timer has worked or the time (in seconds) since it has been started (in case it is still working). Format name:seconds or only seconds (if the name is an empty string)

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the timer object

_getNow

public long _getNow()
Gets the current system time in milliseconds

Returns:
the current time in milliseconds