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 value of any of the millisecond or nanosecond fields is negative the variable is set to negative value. Although logically 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 parameter to the a 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.


Constructor Summary
RelativeTime()
          Equivalent to new RelativeTime(0,0)
RelativeTime(long millis, int nanos)
          Construct a RelativeTime object which means a time millis milliseconds plus nanos nanoseconds past the Clock time.
RelativeTime(RelativeTime time)
          Make a new RelativeTime object from the given RelativeTime object
 
Method Summary
 AbsoluteTime absolute(Clock clock)
          Convert this time to an absolute time, relative to some clock.
 AbsoluteTime absolute(Clock clock, AbsoluteTime destination)
          Convert this time to an absolute time.
 RelativeTime add(long millis, int nanos)
          Add a specific number of milli and nano seconds to this.
 RelativeTime add(long millis, int nanos, RelativeTime destination)
          Add a specific number of milli and nano seconds to this.
 RelativeTime add(RelativeTime time)
          Return this + time.
 RelativeTime add(RelativeTime time, RelativeTime destination)
          Return this + time.
 void addInterarrivalTo(AbsoluteTime destination)
          Add this time to an AbsoluteTime.
 RelativeTime getInterarrivalTime()
          Return the interarrival time that is the result of dividing this interval by its frequency.
 RelativeTime getInterarrivalTime(RelativeTime destination)
          Return the interarrival time that is the result of dividing this interval by its frequency.
 RelativeTime relative(Clock clock)
          Change the association of this from the currently associated clock to the given clock.
 RelativeTime relative(Clock clock, RelativeTime destination)
          Set the time of this to the time of the given instance of RelativeTime with respect to the given instance of Clock.
 RelativeTime subtract(RelativeTime time)
           
 RelativeTime subtract(RelativeTime time, RelativeTime destination)
           
 java.lang.String toString()
          Return a printable version of this time.
 
Methods inherited from class javax.realtime.HighResolutionTime
compareTo, compareTo, equals, equals, getMilliseconds, getNanoseconds, hashCode, relative, set, set, set, waitForObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RelativeTime

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

RelativeTime

public RelativeTime(long millis,
                    int nanos)
Construct a RelativeTime object which means a time millis milliseconds plus nanos nanoseconds past the Clock time.
Parameters:
millis - The milliseconds component of the time past the Clock time
nanos - The nanoseconds component of the time past the Clock time

RelativeTime

public RelativeTime(RelativeTime time)
Make a new RelativeTime object from the given RelativeTime object
Parameters:
time - The RelativeTime object used as the source for the copy
Method Detail

absolute

public AbsoluteTime absolute(Clock clock,
                             AbsoluteTime destination)
Convert this time to an absolute time. For a RelativeTime, this involved adding the clocks notion of now to this interval and constructing a new AbsoluteTime based on the sum
Overrides:
absolute in class HighResolutionTime
Parameters:
clock - if null, Clock.getRealTimeClock() is used
destination -  

absolute

public AbsoluteTime absolute(Clock clock)
Description copied from class: HighResolutionTime
Convert this time to an absolute time, relative to some clock. Convenient for situations where you really need an absolute time. Allocates a destination object if necessary. See the derived class comments for more specific information.
Overrides:
absolute in class HighResolutionTime
Following copied from class: javax.realtime.HighResolutionTime
Parameters:
clock - This clock is used to convert this time into absolute time.

relative

public RelativeTime relative(Clock clock)
Change the association of this from the currently associated clock to the given clock.
Overrides:
relative in class HighResolutionTime

relative

public RelativeTime relative(Clock clock,
                             RelativeTime destination)
Set the time of this to the time of the given instance of RelativeTime with respect to the given instance of Clock.

add

public RelativeTime add(long millis,
                        int nanos)
Add a specific number of milli and nano seconds to this. A new object is allocated
Parameters:
millis - milli seconds to add
nanos - nano seconds to add
Returns:
A new object containing the result

add

public RelativeTime add(long millis,
                        int nanos,
                        RelativeTime destination)
Add a specific number of milli and nano seconds to this. A new object is allocated if destination is null, otherwise store there.
Parameters:
millis - milli seconds to add
nanos - nano seconds to add
destination - to store the result
Returns:
A new object containing the result

add

public final RelativeTime add(RelativeTime time)
Return this + time. A new object is allocated for the result.
Parameters:
time - the time to add to this
Returns:
the result

add

public RelativeTime add(RelativeTime time,
                        RelativeTime destination)
Return this + time. If destination is non-null, the result is placed there and dest is returned. Otherwise a new object is allocated for the result.
Parameters:
time - the time to add to this
destination - to place the result in
Returns:
the result

addInterarrivalTo

public void addInterarrivalTo(AbsoluteTime destination)
Add this time to an AbsoluteTime. It is almost the same dest.add(this, dest) except that it accounts for(ie. divides by) the frequency. If destination is equal to null, NullPointerException is thrown.
Parameters:
destination -  

getInterarrivalTime

public RelativeTime getInterarrivalTime()
Return the interarrival time that is the result of dividing this interval by its frequency. For a RelativeTime, and RationalTimes with a frequency of 1, it just returns this. The interarrival time is necessarily an approximation.

getInterarrivalTime

public RelativeTime getInterarrivalTime(RelativeTime destination)
Return the interarrival time that is the result of dividing this interval by its frequency. For a RelativeTime, or a RationalTime with a frequency of 1 it just returns this. The interarrival time is necessarily an approximation.
Parameters:
destination - interarrival time is between this and the destination
Returns:
interarrival time

subtract

public final RelativeTime subtract(RelativeTime time)
Parameters:
time - relative time to subtract from this
Returns:
this-time. A new object is allocated for the result.

subtract

public RelativeTime subtract(RelativeTime time,
                             RelativeTime destination)
Parameters:
time - relative time to subtract from this
destination - place to store the result. New object allocated if null
Returns:
this-time. A new object is allocated for the result.

toString

public java.lang.String toString()
Return a printable version of this time. Overrides: java.lang.Object.toString() in class java.lang.Object
Overrides:
toString in class java.lang.Object
Returns:
String a printable version of this time.