javax.realtime
Class RelativeTime

java.lang.Object
  |
  +--javax.realtime.HighResolutionTime
        |
        +--javax.realtime.RelativeTime
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. 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. All Implemented Interfaces: java.lang.Comparable Direct Known Subclasses: RationalTime


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)
           
 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)
          The purpose of "destination" is unclear, for the result is returned anyway.
 void addInterarrivalTo(AbsoluteTime destination)
          Add this time to an AbsoluteTime.
 RelativeTime getInterarrivalTime(RelativeTime destination)
          Return the interarrival time that is the result of dividing this interval by its frequency.
 RelativeTime relative(Clock clock)
           
 RelativeTime relative(Clock clock, RelativeTime destination)
           
 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, 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 invovled 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)
Overrides:
absolute in class HighResolutionTime

relative

public RelativeTime relative(Clock clock)
Overrides:
relative in class HighResolutionTime

relative

public RelativeTime relative(Clock clock,
                             RelativeTime destination)
Overrides:
relative in class HighResolutionTime

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)
The purpose of "destination" is unclear, for the result is returned anyway. 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(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.