|
|||||||||
| Home >> All >> [ desmoj overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
desmoj
Class TimeConverter

java.lang.Objectdesmoj.TimeConverter
- All Implemented Interfaces:
- Units
- class TimeConverter
- extends java.lang.Object
- implements Units
- extends java.lang.Object
TimeConverter is a class used by Experiment to convert sim time values
to true time values and vice versa. A true time value is a point in "real"
time specified as a String consisting of a date and a time,
for example "26.3.2001 13:25". In order to map the sim time values to
true time values a reference time and a time unit are needed.
The class TimeConverter implements the interface
Units to easily use the time units and conversion factors
defined there.
Every experiment has its own time converter and provides methods for
time conversion. The TimeConverter class is not intended for
direct use in model components because handling of (simulation) time should
be done in experiments only.
Instead, if a model component needs to convert true time values to sim time
or vice versa it has to call the appropriate methods of the class
Experiment.
- Version:
- DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL
| Field Summary | |
(package private) static java.lang.String |
DEFAULT_DATE
The default date used for true time values is 1.1.1970. |
(package private) static java.lang.String |
DEFAULT_PATTERN
The default output format pattern for true time values as a constant. |
(package private) static java.lang.String |
DEFAULT_TIME
The default time used for true time values is 0:00:00. |
(package private) static int |
DEFAULT_UNIT
The default time unit is Units.MIN. |
private long |
offset
The interval between reference time (= start time of simulation) and default time of class java.util.Date (= 1.1.1970 0:00:00)
in milliseconds. |
private java.text.SimpleDateFormat |
outFormat
The output formatter for true time values. |
private double |
startSimTime
The start time of the simulation as double (sim time). |
private int |
unit
The reference time unit as a constant defined in interface Units. |
| Fields inherited from interface desmoj.Units |
CM, H, KM, KM_H, M, M_S, MIN, MM, MS, S, unitFactors, unitStrings |
| Constructor Summary | |
TimeConverter()
Default constructor for a time converter using the defined constants as default values for reference time (1.1.1970 0:00:00) and reference time unit (minutes). |
|
TimeConverter(java.lang.String referenceTime,
int referenceUnit)
Constructs a time converter with given reference time and reference unit. |
|
| Method Summary | |
private java.lang.String |
checkRefTime(java.lang.String refTime)
Checks if the given reference time is complete. |
private java.lang.String |
constructPattern(java.lang.String timeString)
Constructs a pattern to be used for parsing the given timeString. |
java.lang.String |
getReferenceTime()
Returns the reference time as as String formatted as defined in the default output format pattern. |
int |
getReferenceUnit()
Returns the reference time unit as a constant defined in the
Units interface. |
void |
resetTimeFormat()
Resets the time format used to format true time values to the default pattern. |
void |
setStartSimTime(double initTime)
Sets the start time of the simulation to initTime. |
void |
setTimeFormat(java.lang.String pattern)
Sets the time format used to format true time values. |
SimTime |
toSimTime(double duration,
int unit)
Converts the given duration with the given time unit into a sim time value. |
SimTime |
toSimTime(java.lang.String trueTime)
Converts the given true time value to the corresponding sim time value. |
java.lang.String |
toTrueTime(SimTime simTime)
Converts the given sim time value to the corresponding true time value. |
java.lang.String |
toTrueTime(SimTime simTime,
java.lang.String pattern)
Converts the given sim time value to the corresponding true time value using the given pattern as time format. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
DEFAULT_PATTERN
static final java.lang.String DEFAULT_PATTERN
- The default output format pattern for true time values as a constant.
Specified according to the time format syntax used in the
java.text.SimpleDateFormatclass.- See Also:
- Constant Field Values
DEFAULT_DATE
static final java.lang.String DEFAULT_DATE
- The default date used for true time values is 1.1.1970.
- See Also:
- Constant Field Values
DEFAULT_TIME
static final java.lang.String DEFAULT_TIME
- The default time used for true time values is 0:00:00.
- See Also:
- Constant Field Values
DEFAULT_UNIT
static final int DEFAULT_UNIT
- The default time unit is
Units.MIN.- See Also:
- Constant Field Values
offset
private long offset
- The interval between reference time (= start time of simulation)
and default time of class
java.util.Date(= 1.1.1970 0:00:00) in milliseconds.
unit
private int unit
- The reference time unit as a constant defined in interface
Units.
outFormat
private java.text.SimpleDateFormat outFormat
- The output formatter for true time values. Uses the default pattern
if no other pattern is specified via call of the
setTimeFormat 55 method.
startSimTime
private double startSimTime
- The start time of the simulation as double (sim time).
Default is 0.0.
| Constructor Detail |
TimeConverter
public TimeConverter()
throws java.text.ParseException
- Default constructor for a time converter using the defined constants
as default values for reference time (1.1.1970 0:00:00) and reference
time unit (minutes).
TimeConverter
public TimeConverter(java.lang.String referenceTime, int referenceUnit) throws java.text.ParseException
- Constructs a time converter with given reference time and reference
unit. The reference time String should follow the format:
<date><blank><time> with <date> = [d]d.[M]M.[yy]yy and
<time> = [H]H[:[m]m[:[s]s[:[S][S]S]]]
| Method Detail |
checkRefTime
private java.lang.String checkRefTime(java.lang.String refTime)
- Checks if the given reference time is complete. A complete true time
value consists of <date><blank><time> with
<date> = [d]d.[M]M.[yy]yy and
<time> = [H]H[:[m]m[:[s]s[:[S][S]S]]].
If date or time is missing, the default values are used instead.
constructPattern
private java.lang.String constructPattern(java.lang.String timeString)
- Constructs a pattern to be used for parsing the given timeString.
This private helper method is called in any of the above methods
when a true time parameter has to be parsed.
The following assumptions are made:
- timeString consists of a date and a time separated by a blank (<date> <time>)
- <date> has the format [d]d.[M]M.[yy]yy
- <time> has the format [H]H[:[m]m[:[s]s[:[S][S]S]]]
SimpleDateFormatclass can use "minimal" patterns (for example: the pattern "d.M.yy" is okay for all dates consisting of 1 or 2 day digits, 1 or 2 month digits, and 2 or 4 year digits, separated by dots) the date format is no problem. But the time has to be checked on the number of elements (hours, minutes, seconds, milliseconds) used in order to construct the appropriate pattern.
getReferenceTime
public java.lang.String getReferenceTime()
- Returns the reference time as as String formatted as defined in the
default output format pattern. A different format may be specified
via call of the
setTimeFormat(String)method.
getReferenceUnit
public int getReferenceUnit()
- Returns the reference time unit as a constant defined in the
Unitsinterface.
resetTimeFormat
public void resetTimeFormat()
- Resets the time format used to format true time values to the default
pattern.
setStartSimTime
public void setStartSimTime(double initTime)
- Sets the start time of the simulation to
initTime. This method must be called if a start time other than 0.0 is used.
setTimeFormat
public void setTimeFormat(java.lang.String pattern)
- Sets the time format used to format true time values. Initially, the
default pattern is used for formatting.
toSimTime
public SimTime toSimTime(double duration, int unit)
- Converts the given duration with the given time unit into a sim time
value. The duration is interpreted as the interval between sim time
0.0 and the calculated sim time value.
toSimTime
public SimTime toSimTime(java.lang.String trueTime) throws java.text.ParseException
- Converts the given true time value to the corresponding sim time value.
toTrueTime
public java.lang.String toTrueTime(SimTime simTime)
- Converts the given sim time value to the corresponding true time value.
toTrueTime
public java.lang.String toTrueTime(SimTime simTime, java.lang.String pattern)
- Converts the given sim time value to the corresponding true time value
using the given pattern as time format.
|
|||||||||
| Home >> All >> [ desmoj overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
desmoj.TimeConverter