laur.tools
Class Timer

java.lang.Object
  |
  +--laur.tools.Timer

public class Timer
extends java.lang.Object

This class implements a timer. The timer can be in one of two states: started or stopped. Method start() makes a transition from stopped to started, and method stop() does a transition from started to stopped. Method time() can be used to get the total time measured by the timer and it can be called when the timer is in either of the two states. Method reset() will reset the timer; if the timer was running then it will continue to run but it will measure time from the moment we called reset(), if the timer was stopped, the time measured will be reset to 0.


Constructor Summary
Timer()
          Initialize a new timer.
 
Method Summary
 boolean isStarted()
          This method should be called to find out if the timer is started or not.
 void reset()
          This method should be called to reset the timer.
 void start()
          This method should be called to start/restart the timer.
 void stop()
          This method should be called to stop/pause the timer.
 long time()
          This method should be called to find out the time measured so far.
 java.lang.String toString()
          This method returns a string representation of our timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
Initialize a new timer.

Method Detail

start

public void start()
This method should be called to start/restart the timer. If the timer was already started then this won't do anything, otherwise the timer will be started.


stop

public void stop()
This method should be called to stop/pause the timer. If the timer wasn't started then this won't do anything, otherwise the timer will be stoped.


reset

public void reset()
This method should be called to reset the timer. If the timer was started then it will continue running but it will measure the time starting from now. If the timer wasn't started then the method will just reset the time measured so far to 0.


time

public long time()
This method should be called to find out the time measured so far. If the timer is started then the time measured up to this precise moment will be returned. If the timer was stopped then the time measured up to the time it was stopped will be returned. The time is measured in milliseconds.

Returns:
the measured time in milliseconds

isStarted

public boolean isStarted()
This method should be called to find out if the timer is started or not.

Returns:
true if timer is started, false otherwise

toString

public java.lang.String toString()
This method returns a string representation of our timer.

Overrides:
toString in class java.lang.Object