|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.actor.util.Time
public class Time
An object of the Time class represents model time, as distinct from "wall-clock time," which is time in the physical world. An instance of Time has a value that is immutable. It has no limit on the magnitude. There are two time constants: NEGATIVE_INFINITY and POSITIVE_INFINITY.
The time value is quantized to the time resolution specified by the timeResolution parameter of the associated director. The reason for this is that without quantization, it is extremely difficult to compare two time values with digit-to-digit accuracy because of the unpredictable numerical errors introduced during computation. In practice, two time values can only be distinguished if their difference can be detected by some measuring instrument, which always has a smallest unit for measurement. This smallest unit measurement gives the physical meaning of the time resolution used for quantization.
The time value can be retrieved in three ways, the toString()
method
and the getDoubleValue()
method and the getLongValue()
method. The first method returns a string representation while the second
method returns a double value. There are some limitations on both methods.
For the toString() method, we can not directly do numerical operations on
strings. For the getDoubleValue() method, we can not guarantee that the
returned double value preserves the time resolution because of the limited
digits for double representation. We recommend to operate on time objects
directly instead of the time values of time objects. getLongValue() returns
an integer multiple of the director resolution.
Two operations, add and subtract, can be performed on a time object, where the argument can be a double or a time object. If the argument is not a time object, the argument is quantized before the operations are performed. These operations return a new time object with a quantized result.
The time value of a time object can be infinite. The add and subtract operations on infinite time values follow rules similar to the IEEE Standard 754 for Floating Point Numbers. In particular, adding two positive/negative infinities yield a positive/negative infinity; adding a positive infinity and a negative infinity, however, triggers an ArithmeticException; the negation of a positive/negative infinity is a negative/positive infinity. The following link gives a list of operations, http://en.wikipedia.org/wiki/Infinity.
This class implements the Comparable interface, where two time objects can be compared in the following way. If any of the two time objects contains an infinite time value, the rules are: a negative infinity is equal to a negative infinity and less than anything else; a positive infinity is equal to a positive infinity and bigger than anything else. If none of the time objects has an infinite time value, the time values of two time objects are compared. If the time values are the same, the two time objects are treated equal, or they represent the same model time. Otherwise, the time object containing a bigger time value is regarded to happen after the time object with a smaller time value.
All time objects share the same time resolution, which is provided by the top-level director. In some domains, such as CT and DE, users can change the time resolution by configuring the timeResolution parameter. The default value for this parameter "1E-10", which has value 10 -10 . To preserve the consistency of time values, timeResolution can not be changed when a model is running (attempting to do so will trigger an exception).
Red (hyzheng) |
Yellow (hyzheng) |
Field Summary | |
---|---|
private Director |
_director
The director that this time object is associated with. |
private boolean |
_isNegativeInfinite
A boolean variable is true if the time value is a negative infinity. |
private boolean |
_isPositiveInfinite
A boolean variable is true if the time value is a positive infinity. |
private static int |
_NEGATIVE_INFINITY
|
private static int |
_POSITIVE_INFINITY
|
private java.math.BigInteger |
_timeValue
The time value, as a multiple of the resolution. |
static Time |
NEGATIVE_INFINITY
A static and final time constant holding a negative infinity. |
static Time |
POSITIVE_INFINITY
A static and final time constant holding a positive infinity. |
Constructor Summary | |
---|---|
|
Time(Director director)
Construct a Time object with zero as the time value. |
private |
Time(Director director,
java.math.BigInteger timeValue)
Construct a Time object with the specified BigInteger value as its time value (as a multiple of the precision). |
|
Time(Director director,
double timeValue)
Construct a Time object with the specified double value as its time value. |
|
Time(Director director,
long timeValue)
Construct a Time object with the specified long value as its time value. |
private |
Time(int value)
Construct a Time object with value that is one of _POSITIVE_INFINITY or _NEGATIVE_INFINITY. |
Method Summary | |
---|---|
private java.math.BigInteger |
_doubleToMultiple(double value)
Given a double, return the BigInteger that represents its quantized value. |
protected double |
_timeResolution()
Return the time resolution for this Time object, which in this class is the time resolution of the director given in the constructor. |
Time |
add(double timeValue)
Return a new time object whose time value is increased by the given double value. |
Time |
add(Time time)
Return a new time object whose time value is the sum of that of this time object and of the specified time object. |
int |
compareTo(java.lang.Object time)
Return -1, 0, or 1 if this time object is less than, equal to, or greater than the given argument. |
boolean |
equals(java.lang.Object time)
Return true if this time object has the same time value as that of the given time object. |
double |
getDoubleValue()
Return the double representation of the time value of this time object. |
long |
getLongValue()
Return the long representation of the time value of this time object. |
int |
hashCode()
Return the hash code for the time object. |
boolean |
isInfinite()
Return true if the current time value is infinite. |
boolean |
isNegativeInfinite()
Return true if the current time value is a negative infinity. |
boolean |
isPositiveInfinite()
Return true if the current time value is a positive infinity. |
double |
maximumAccurateValueAsDouble()
Return the maximum value of time whose representation as a double is always accurate to the specified time resolution. |
Time |
subtract(double timeValue)
Return a new time object whose time value is decreased by the given double value. |
Time |
subtract(Time time)
Return a new time object whose time value is decreased by the time value of the specified time object. |
java.lang.String |
toString()
Return the string representation of this time object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static int _NEGATIVE_INFINITY
private static int _POSITIVE_INFINITY
public static final Time NEGATIVE_INFINITY
public static final Time POSITIVE_INFINITY
private Director _director
private boolean _isPositiveInfinite
private boolean _isNegativeInfinite
private java.math.BigInteger _timeValue
Constructor Detail |
---|
public Time(Director director)
director
- The director with which this time object is associated.
This must not be null, or subsequent uses of the class will fail.public Time(Director director, double timeValue) throws IllegalActionException
director
- The director with which this time object is associated.timeValue
- A double value as the specified time value.
java.lang.ArithmeticException
- If the argument is NaN.
IllegalActionException
- If the given double time value does
not match the time resolution.public Time(Director director, long timeValue)
director
- The director with which this time object is associated.timeValue
- A long value as the specified time value, as a multiple
of the resolution.private Time(Director director, java.math.BigInteger timeValue)
director
- The director with which this time object is associated.timeValue
- The multiple of the precsision that is the time value.private Time(int value)
value
- One of _POSITIVE_INFINITY or _NEGATIVE_INFINITY.Method Detail |
---|
public Time add(double timeValue)
timeValue
- The amount of the time increment.
java.lang.ArithmeticException
- If the result is not a valid
number (the argument is NaN or the sum would be), or the given time
value does not match the time resolution.public Time add(Time time)
time
- The time object contains the amount of time increment.
java.lang.ArithmeticException
- If the result is not a valid number
(it is the sum of positive and negative infinity).public int compareTo(java.lang.Object time)
compareTo
in interface java.lang.Comparable
time
- A time object to compare to.
public boolean equals(java.lang.Object time)
equals
in class java.lang.Object
time
- The time object that this time object is compared to.
public double getDoubleValue()
public long getLongValue()
public int hashCode()
hashCode
in class java.lang.Object
public final boolean isInfinite()
public final boolean isNegativeInfinite()
public final boolean isPositiveInfinite()
public double maximumAccurateValueAsDouble()
public Time subtract(double timeValue)
timeValue
- The amount of time decrement.
public Time subtract(Time time)
time
- The time object contains the amount of time decrement.
public java.lang.String toString()
toString
in class java.lang.Object
protected double _timeResolution()
private java.math.BigInteger _doubleToMultiple(double value) throws IllegalActionException
value
- The value as a double.
IllegalActionException
- If the given double time value does
not match the time resolution.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |