Search this API

y.util
Class Timer

java.lang.Object
  extended by y.util.Timer

public class Timer
extends java.lang.Object

Provides timer functionality. A timer is can either be in an activated or stopped state. A timer can sum up the time elapsed while it is in an activated state.

 

Constructor Summary
Timer()
          Creates a new instance of a timer.
Timer(boolean activate)
          Creates a new instance of a timer, initially active or not.
 
Method Summary
 long getElapsedTime()
          Returns the period of time the timer has been in an activated state since the last reset occurred.
 boolean isActive()
          Returns whether or not this timer is active right now.
 boolean isStopped()
          Returns whether or not this timer is stopped (not active) right now.
 void reset()
          Resets the elapsed time to 0.
 void start()
          Starts or restarts this timer, if not already running.
 void stop()
          Stops this timer, if not already stopped.
 void toggle()
          Toggles the activation state if this timer.
 java.lang.String toString()
          Returns the elapsed time as String in a minutes, seconds, milliseconds format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
Creates a new instance of a timer. The timer is initially active.


Timer

public Timer(boolean activate)
Creates a new instance of a timer, initially active or not.

Parameters:
activate - whether or not the timer should be initially active.
Method Detail

start

public void start()
Starts or restarts this timer, if not already running. The time elapsed will not be reset by this method.


stop

public void stop()
Stops this timer, if not already stopped.


toggle

public void toggle()
Toggles the activation state if this timer.


getElapsedTime

public long getElapsedTime()
Returns the period of time the timer has been in an activated state since the last reset occurred.


isActive

public boolean isActive()
Returns whether or not this timer is active right now.


isStopped

public boolean isStopped()
Returns whether or not this timer is stopped (not active) right now.


reset

public final void reset()
Resets the elapsed time to 0. This method does not change the state (running or not) of this timer.


toString

public final java.lang.String toString()
Returns the elapsed time as String in a minutes, seconds, milliseconds format.

Overrides:
toString in class java.lang.Object

© Copyright 2000-2017,
yWorks GmbH.
All rights reserved.