de.jaret.util.date.timemachine
Class TimeMachine

java.lang.Object
  extended by de.jaret.util.date.timemachine.TimeMachine
All Implemented Interfaces:
ITimeProvider

public class TimeMachine
extends Object
implements ITimeProvider

Implementation of a time supplier that can be controlled by various options. This is useful to cut dependencies on system time. The class should usually be used as a singleton, but is no singleton itself.

Version:
$Id: TimeMachine.java 702 2007-12-30 11:54:55Z kliem $
Author:
kliem

Constructor Summary
TimeMachine(long initialTime)
          Construct the time machine with an initial time.
 
Method Summary
 void addTimeMachineListener(ITimeMachineListener timeMachineListener)
          Add a listener to the timemachine.
protected  void fireTimeChanged(long oldTime, long newTime)
          Inform listeners about a change.
 Date getCurentTimeAsDate()
          Retrieve the current time as a Date object.
 long getCurrentTime()
          Retrieve the current time.
 boolean isAutoIncrement()
          If autoincrement is true the time will be incremented by 1 millisecond with each time request.
 boolean isForwardOnly()
          true if the time will always be going towards the future.
 boolean isRealTime()
          If this return true the time machine is in real time mode always providing the system's current time.
 void remTimeMachineListener(ITimeMachineListener timeMachineListener)
          Remove a listener from the time machine.
 void setAutoIncrement(boolean autoIncrement)
          set autoincrement mode.
 void setForwardOnly(boolean forwardOnly)
          Set forward protection: if set to true time shifts going before the current time will be disallowed.
 void setRealTime(boolean realTime)
          Set the realtime mode.
 void setTime(long time)
          Set the time of the timemachine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeMachine

public TimeMachine(long initialTime)
Construct the time machine with an initial time.

Parameters:
initialTime - time (millis)
Method Detail

getCurrentTime

public long getCurrentTime()
Retrieve the current time. base method that supplies the timea nd might auto increment the time value.

Specified by:
getCurrentTime in interface ITimeProvider
Returns:
current time as millis.

getCurentTimeAsDate

public Date getCurentTimeAsDate()
Retrieve the current time as a Date object. Wraps millis from getCurrentTime in a Date object.

Specified by:
getCurentTimeAsDate in interface ITimeProvider
Returns:
current time as java.util.Date

setTime

public void setTime(long time)
Set the time of the timemachine.

Parameters:
time - millis

addTimeMachineListener

public void addTimeMachineListener(ITimeMachineListener timeMachineListener)
Add a listener to the timemachine.

Parameters:
timeMachineListener - time machine listener

remTimeMachineListener

public void remTimeMachineListener(ITimeMachineListener timeMachineListener)
Remove a listener from the time machine.

Parameters:
timeMachineListener - listener to remove

fireTimeChanged

protected void fireTimeChanged(long oldTime,
                               long newTime)
Inform listeners about a change.

Parameters:
oldTime - last time
newTime - current (= new) time

isForwardOnly

public boolean isForwardOnly()
true if the time will always be going towards the future.

Returns:
true for ongoing time only

setForwardOnly

public void setForwardOnly(boolean forwardOnly)
Set forward protection: if set to true time shifts going before the current time will be disallowed. Forward only is the default.

Parameters:
forwardOnly - true for forward only mode.

isAutoIncrement

public boolean isAutoIncrement()
If autoincrement is true the time will be incremented by 1 millisecond with each time request.

Returns:
true if autoincrement is set

setAutoIncrement

public void setAutoIncrement(boolean autoIncrement)
set autoincrement mode.

Parameters:
autoIncrement - if sert to true the time will be increased by 1 millisecond which each request

isRealTime

public boolean isRealTime()
If this return true the time machine is in real time mode always providing the system's current time.

Returns:
true for real time mode

setRealTime

public void setRealTime(boolean realTime)
Set the realtime mode.

Parameters:
realTime - if set to true the time machine will be disabled, always returning the systems's current time


Copyright © 2013. All Rights Reserved.