javax.realtime
Class RelativeTime

java.lang.Object
  |
  +--javax.realtime.HighResolutionTime
        |
        +--javax.realtime.RelativeTime
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
RationalTime

public class RelativeTime
extends HighResolutionTime

An object that represents a time interval millis/1E3+nanos/1E9 seconds long. It generally is used to represent a time relative to now.

If the values of any of the millisecond or nanosecond fields is negative the variable is set to negative value. Although logically, and correctly, this may represent time before the epoch, invalid results may occur if an instance of RelativeTime representing time before the epoch is given as a paramter to some method. For add and subtract negative values behave just like they do in arithmetic.

Caution: This class is explicitly unsafe in multithreaded situations when it is being changed. No synchronization is done. It is assumed that users of this class who are mutating instances will be doing their own synchronization at a higher level


Field Summary
static javax.realtime.RelativeTime ZERO
           
 
Fields inherited from class javax.realtime.HighResolutionTime
defaultClock
 
Constructor Summary
RelativeTime()
          Equivalent to new RelativeTime(0, 0).
RelativeTime(long millis, int nanos)
          Constructs a RelativeTime object representing an interval defined by the given parameter values.
RelativeTime(javax.realtime.RelativeTime t)
          Make a new RelativeTime object from the given RelativeTime object.
 
Method Summary
 javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock)
          Convert the time given by this to an absolute time.
 javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock, javax.realtime.AbsoluteTime destination)
          Convert the time given by this to an absolute time.
 javax.realtime.RelativeTime add(long millis, int nanos)
          Add a specific number of milliseconds and nanoseconds to the appropriate fields of this.
 javax.realtime.RelativeTime add(long millis, int nanos, javax.realtime.RelativeTime destination)
          Add a specific number of milliseconds and nanoseconds to the appropriate fields of this.
 javax.realtime.RelativeTime add(javax.realtime.RelativeTime time)
          Add the interval of this to the interval of the given instance of RelativeTime.
 javax.realtime.RelativeTime add(javax.realtime.RelativeTime time, javax.realtime.RelativeTime destination)
          Add the interval of this to the interval of the given instance of RelativeTime.
 void addInterarrivalTo(javax.realtime.AbsoluteTime destination)
          Add the interval of this to the given instance of AbsoluteTime.
 javax.realtime.RelativeTime getInterarrivalTime()
          Gets the interval defined by this.
 javax.realtime.RelativeTime getInterarrivalTime(javax.realtime.RelativeTime destination)
          Gets the interval defined by this For an instance of RelativeTime it is the interval divided by the frequency.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock)
          Make a new RelativeTime object from the time given by this but based on the given instance of Clock.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock, javax.realtime.HighResolutionTime time)
          Make a new RelativeTime object from the time given by this but based on the given instance of Clock.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock, javax.realtime.RelativeTime time)
          Make a new RelativeTime object from the time given by this but based on the given instance of Clock.
 javax.realtime.RelativeTime subtract(javax.realtime.RelativeTime time)
          Subtract the interval defined by the given instance of RelativeTime from the interval defined by this.
 javax.realtime.RelativeTime subtract(javax.realtime.RelativeTime time, javax.realtime.RelativeTime destination)
          Subtract the interval defined by the given instance of RelativeTime from the interval defined by this.
 java.lang.String toString()
          Return a printable version of the time defined by this.
 
Methods inherited from class javax.realtime.HighResolutionTime
compareTo, compareTo, equals, equals, getMilliseconds, getNanoseconds, hashCode, set, set, set, time, waitForObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static javax.realtime.RelativeTime ZERO
Constructor Detail

RelativeTime

public RelativeTime()
Equivalent to new RelativeTime(0, 0).


RelativeTime

public RelativeTime(long millis,
                    int nanos)
Constructs a RelativeTime object representing an interval defined by the given parameter values.

Parameters:
millis - The milliseconds component.
nanos - The nanoseconds component.

RelativeTime

public RelativeTime(javax.realtime.RelativeTime t)
Make a new RelativeTime object from the given RelativeTime object.

Parameters:
t - The RelativeTime object used as the source for the copy.
Method Detail

absolute

public javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock)
Convert the time given by this to an absolute time. The calculation is the current time indicated by the given instance of Clock plus the interval given by this.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The given instance of Clock If null, Clock.getRealTimeClock() is used.
Returns:
The new instance of AbsoluteTime containing the result.

absolute

public javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock,
                                            javax.realtime.AbsoluteTime destination)
Convert the time given by this to an absolute time. The calculation is the current time indicated by the given instance of Clock plus the interval given by this.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The given instance of Clock If null, Clock.getRealTimeClock() is used.
destination - A reference to the result instance of AbsoluteTime.
Returns:
The new instance of AbsoluteTime containing the result.

add

public javax.realtime.RelativeTime add(long millis,
                                       int nanos)
Add a specific number of milliseconds and nanoseconds to the appropriate fields of this. A new object is allocated.

Parameters:
millis - The number of milliseconds to add.
nanos - The number of nanoseconds to add.
Returns:
A new object containing the result of the addition.

add

public javax.realtime.RelativeTime add(long millis,
                                       int nanos,
                                       javax.realtime.RelativeTime destination)
Add a specific number of milliseconds and nanoseconds to the appropriate fields of this. A new object is allocated.

Parameters:
millis - The number of milliseconds to add.
nanos - The number of nanoseconds to add.
destination - A reference to the result instance of RelativeTime.
Returns:
A new object containing the result of the addition

add

public final javax.realtime.RelativeTime add(javax.realtime.RelativeTime time)
Add the interval of this to the interval of the given instance of RelativeTime.

Parameters:
time - A reference to the given instance of RelativeTime.
Returns:
A new object containing the result of the addition.

add

public javax.realtime.RelativeTime add(javax.realtime.RelativeTime time,
                                       javax.realtime.RelativeTime destination)
Add the interval of this to the interval of the given instance of RelativeTime.

Parameters:
time - A reference to the given instance of RelativeTime.
destination - A reference to the result instance of RelativeTime.
Returns:
A new object containing the result of the addition.

addInterarrivalTo

public void addInterarrivalTo(javax.realtime.AbsoluteTime destination)
Add the interval of this to the given instance of AbsoluteTime.

Parameters:
destination - A reference to the given instance of AbsoluteTime and the result.

getInterarrivalTime

public javax.realtime.RelativeTime getInterarrivalTime()
Gets the interval defined by this. For an instance of RationalTime it is the interval divided by the frequency.

Returns:
A reference to a new instance of RelativeTime with the same interval as this.

getInterarrivalTime

public javax.realtime.RelativeTime getInterarrivalTime(javax.realtime.RelativeTime destination)
Gets the interval defined by this For an instance of RelativeTime it is the interval divided by the frequency.

Parameters:
destination - A reference to the new object holding the result.
Returns:
A reference to an object holding the result.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock)
Make a new RelativeTime object from the time given by this but based on the given instance of Clock.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The given instance of Clock.
Returns:
A reference to the new instance of RelativeTime.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock,
                                            javax.realtime.RelativeTime time)
Make a new RelativeTime object from the time given by this but based on the given instance of Clock.

Parameters:
clock - The given instance of Clock.
time - A reference to the result instance of RelativeTime.
Returns:
A reference to the new instance of RelativeTime.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock,
                                            javax.realtime.HighResolutionTime time)
Make a new RelativeTime object from the time given by this but based on the given instance of Clock.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The given instance of Clock.
time - A reference to the result instance of RelativeTime.
Returns:
A reference to the new instance of HighResolutionTime.

subtract

public final javax.realtime.RelativeTime subtract(javax.realtime.RelativeTime time)
Subtract the interval defined by the given instance of RelativeTime from the interval defined by this.

Parameters:
time - A reference to the given instance of RelativeTime.
Returns:
A new object holding the result of the subtraction.

subtract

public javax.realtime.RelativeTime subtract(javax.realtime.RelativeTime time,
                                            javax.realtime.RelativeTime destination)
Subtract the interval defined by the given instance of RelativeTime from the interval defined by this.

Parameters:
time - A reference to the given instance of RelativeTime.
destination - A reference to the object holding the result.
Returns:
A new object holding the result of the subtraction.

toString

public java.lang.String toString()
Return a printable version of the time defined by this.

Overrides:
toString in class java.lang.Object
Returns:
An instance of java.lang.String representing the time defined by this.