TaxiProject05.environment
Class SimTime

java.lang.Object
  extended by TaxiProject05.environment.SimTime
All Implemented Interfaces:
java.io.Serializable

public class SimTime
extends java.lang.Object
implements java.io.Serializable

Holds the time in the simulation. Thread safe. Examples: //get current time double timemillis = SimTime.getInstance().getCurrentTimeMillis(); Date d = SimTime.getInstance().getCurrentDate(); //change speed of simulation SimTime.getInstance().setTimeFactor(SimTime.TimeFactor_Fast);

Author:
Christian Falk
See Also:
Serialized Form

Field Summary
static long TimeFactor_Fast
          Timefactor for slow speed (x60 from realtime)
static long TimeFactor_Normal
          Timefactor for slow speed (x60 from realtime)
static long TimeFactor_Pause
          Tidsfaktor som används för paus
static long TimeFactor_RealTime
          Timefactor for realtime speed
static long TimeFactor_Slow
          Timefactor for slow speed (x60 from realtime)
 
Method Summary
 java.util.Date getCurrentDate()
          Gets the current Date in the simulation.
 long getCurrentTimeMillis()
          Get the current time in the simulation. in
static SimTime getInstance()
          Use this -> Get the singleton instance.
 java.util.Date getRealDate(java.util.Date d)
          Converts a simulation time to a real system time.
 long getTimeFactor()
           
 void resetTime()
          Nollställer tiden till standard-starttiden.
 void setAlarm(java.util.TimerTask task, java.util.Date time)
          Schedule a timer task to a specific time.
 void setTime(long t)
          Sets the simulation time to a specific datetime.
 void setTimeFactor(long timeFactor)
          Change the factor for the time simulation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TimeFactor_Pause

public static final long TimeFactor_Pause
Tidsfaktor som används för paus

See Also:
Constant Field Values

TimeFactor_RealTime

public static final long TimeFactor_RealTime
Timefactor for realtime speed

See Also:
Constant Field Values

TimeFactor_Slow

public static final long TimeFactor_Slow
Timefactor for slow speed (x60 from realtime)

See Also:
Constant Field Values

TimeFactor_Normal

public static final long TimeFactor_Normal
Timefactor for slow speed (x60 from realtime)

See Also:
Constant Field Values

TimeFactor_Fast

public static final long TimeFactor_Fast
Timefactor for slow speed (x60 from realtime)

See Also:
Constant Field Values
Method Detail

getInstance

public static SimTime getInstance()
Use this -> Get the singleton instance.

Returns:
The single instance of Environment class.

resetTime

public void resetTime()
Nollställer tiden till standard-starttiden.


setTime

public void setTime(long t)
Sets the simulation time to a specific datetime.

Parameters:
t - the time to set to in millis. Date.getTime().

getTimeFactor

public long getTimeFactor()
Returns:
Returns the timeFactor.

setTimeFactor

public void setTimeFactor(long timeFactor)
Change the factor for the time simulation. Set it to 1 leads to realtime Set it to 60 leads to 60 times faster, 1 min in the simulations takes 1 sek. Set it to 0 pauses. (Needs testing)

Parameters:
timeFactor - The timeFactor to set.

getCurrentTimeMillis

public long getCurrentTimeMillis()
Get the current time in the simulation. in

Returns:
milliseconds since 1970-01-01 00:00.

getCurrentDate

public java.util.Date getCurrentDate()
Gets the current Date in the simulation. (This includes the time as well)

Returns:
Date in the simulation.

getRealDate

public java.util.Date getRealDate(java.util.Date d)
Converts a simulation time to a real system time.

Parameters:
d - a simulation time.
Returns:
the real system time.

setAlarm

public void setAlarm(java.util.TimerTask task,
                     java.util.Date time)
Schedule a timer task to a specific time. Note: This doesn't work yet when changing the speed of the time!

Parameters:
task - A Task with the method that should be executed the specified time.
time - The time when the task should be done.