JTP
Class TimeStore

java.lang.Object
  extended by JTP.TimeStore

public class TimeStore
extends Object

Class storing timing information (used by GameTimer).

Author:
V.Termanis

Constructor Summary
TimeStore()
           
 
Method Summary
 long getAccumulatedTime()
          Returns time added up by using incrementAccumulatedTime() method.
 long getAccumulatedTimeSeconds()
          Returns time added up by using incrementAccumulatedTime() method, in seconds.
 long getTimeLimit()
          Returns time time limit set.
 boolean hasStarted()
          Returns whether start point has been set.
 void incrementAccumulatedTime()
          Adds the currently leftover time to the total.
 void reset()
          Resets start and stop times.
 void resetAccumulatedTime()
          Resets the time added up by using incrementAccumulatedTime() method back to zero for active timer.
 void resume()
          Adjust start time to take into account pause period caused by call to stop().
 void setTimeLimit(int timeLimit)
          Sets time limit to use.
 void start()
          Sets start time to current timestamp.
 void stop()
          Sets stop time to current timestamp assuming start() has been called before.
 long timeLeft()
          Returns time remaining for given time limit.
 String toString()
          Returns time remaining in mm:ss format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeStore

public TimeStore()
Method Detail

setTimeLimit

public void setTimeLimit(int timeLimit)
                  throws IllegalArgumentException
Sets time limit to use.

Parameters:
timeLimit - time in seconds.
Throws:
IllegalArgumentException - if timeLimit < 0.

getTimeLimit

public long getTimeLimit()
Returns time time limit set.

Returns:
time limit in seconds.

start

public void start()
Sets start time to current timestamp.


hasStarted

public boolean hasStarted()
Returns whether start point has been set.

Returns:
true if start() has been called since construction or last reset() call.

resume

public void resume()
Adjust start time to take into account pause period caused by call to stop().


stop

public void stop()
Sets stop time to current timestamp assuming start() has been called before. A second call to this method without calls to either start() or resume() will have no effect.


getAccumulatedTime

public long getAccumulatedTime()
Returns time added up by using incrementAccumulatedTime() method.

Returns:
accumulated time in milliseconds.

getAccumulatedTimeSeconds

public long getAccumulatedTimeSeconds()
Returns time added up by using incrementAccumulatedTime() method, in seconds. Note: The returned value will have been rounded up to the nearest second.

Returns:
accumulated time in seconds.

incrementAccumulatedTime

public void incrementAccumulatedTime()
Adds the currently leftover time to the total. Note: It only makes sense to call this after the timer has been stopped and before it has been reset.


timeLeft

public long timeLeft()
Returns time remaining for given time limit.

Returns:
time in milliseconds, and never less than zero.

reset

public void reset()
Resets start and stop times.


resetAccumulatedTime

public void resetAccumulatedTime()
Resets the time added up by using incrementAccumulatedTime() method back to zero for active timer.


toString

public String toString()
Returns time remaining in mm:ss format.

Overrides:
toString in class Object
Returns:
time in String representation.