lejos.realtime
Class RelativeTime

java.lang.Object
  extended by lejos.realtime.HighResolutionTime
      extended by lejos.realtime.RelativeTime
All Implemented Interfaces:
Cloneable, Comparable<RelativeTime>

public class RelativeTime
extends HighResolutionTime
implements Cloneable, Comparable<RelativeTime>

Author:
Team iRboT

Constructor Summary
RelativeTime()
          Equivalent to new RelativeTime(0,0).
RelativeTime(Clock clock)
          Equivalent to new RelativeTime(0,0,clock).
RelativeTime(long millis, int nanos)
          Construct a RelativeTime object representing an interval based on the parameter millis plus the parameter nanos.
RelativeTime(long millis, int nanos, Clock clock)
          Construct a RelativeTime object representing an interval based on the parameter millis plus the parameter nanos.
RelativeTime(RelativeTime time)
           
RelativeTime(RelativeTime time, Clock clock)
          Make a new RelativeTime object from the given RelativeTime object.
 
Method Summary
 AbsoluteTime absolute(Clock clock)
          Convert the time of this to an absolute time, using the given instance of Clock to determine the current time when necessary.
 AbsoluteTime absolute(Clock clock, AbsoluteTime dest)
          Convert the time of this to an absolute time, using the given instance of Clock to determine the current time when necessary.
 RelativeTime add(long millis, int nanos)
           
 RelativeTime add(long millis, int nanos, RelativeTime dest)
           
 RelativeTime add(RelativeTime time)
           
 RelativeTime add(RelativeTime time, RelativeTime dest)
           
 void addInterarrivalTo(AbsoluteTime timeAndDestination)
           
 int compareTo(RelativeTime o)
          Compares this with another Object.
 RelativeTime getInterarrivalTime()
           
 RelativeTime getInterarrivalTime(RelativeTime destination)
           
 RelativeTime relative(Clock clock)
          Convert the time of this to a relative time, using the given instance of Clock to determine the current time when necessary.
 RelativeTime relative(Clock clock, RelativeTime dest)
          Convert the time of this to a relative time, using the given instance of Clock to determine the current time when necessary.
 RelativeTime subtract(RelativeTime time)
           
 RelativeTime subtract(RelativeTime time, RelativeTime dest)
           
 String toString()
           
 
Methods inherited from class lejos.realtime.HighResolutionTime
clone, compareTo, compareTo, equals, equals, getClock, getMilliseconds, getNanoseconds, hashCode, set, set, set, waitForObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RelativeTime

public RelativeTime()
Equivalent to new RelativeTime(0,0). The clock association is implicitly made with the real-time clock.


RelativeTime

public RelativeTime(Clock clock)
Equivalent to new RelativeTime(0,0,clock). The clock association is made with the clock parameter. If clock is null the association is made with the real-time clock.

Parameters:
clock - The clock providing the association for the newly constructed object.

RelativeTime

public RelativeTime(long millis,
                    int nanos)
Construct a RelativeTime object representing an interval based on the parameter millis plus the parameter nanos. The construction is subject to millis and nanos parameters normalization. If there is an overflow in the millisecond component when normalizing then an IllegalArgumentException will be thrown. The clock association is implicitly made with the real-time clock.

Parameters:
millis - The desired value for the millisecond component of this. The actual value is the result of parameter normalization.
nanos - The desired value for the nanosecond component of this. The actual value is the result of parameter normalization.
Throws:
IllegalArgumentException - Thrown if there is an overflow in the millisecond component when normalizing.

RelativeTime

public RelativeTime(long millis,
                    int nanos,
                    Clock clock)
Construct a RelativeTime object representing an interval based on the parameter millis plus the parameter nanos. The construction is subject to millis and nanos parameters normalization. If there is an overflow in the millisecond component when normalizing then an IllegalArgumentException will be thrown. The clock association is made with the clock parameter. If clock is null the association is made with the real-time clock.

Parameters:
millis - The desired value for the millisecond component of this. The actual value is the result of parameter normalization.
nanos - The desired value for the nanosecond component of this. The actual value is the result of parameter normalization.
clock - The clock providing the association for the newly constructed object.
Throws:
IllegalArgumentException - Thrown if there is an overflow in the millisecond component when normalizing. Since: 1.0.1

RelativeTime

public RelativeTime(RelativeTime time)

RelativeTime

public RelativeTime(RelativeTime time,
                    Clock clock)
Make a new RelativeTime object from the given RelativeTime object. The clock association is made with the clock parameter. If clock is null the association is made with the real-time clock.

Parameters:
time - The RelativeTime object which is the source for the copy.
clock - The clock providing the association for the newly constructed object.
Throws:
IllegalArgumentException - Thrown if the time parameter is null. Since: 1.0.1
Method Detail

compareTo

public int compareTo(RelativeTime o)
Description copied from interface: Comparable
Compares this with another Object. Returns -1 if this object is smaller, 0 if both objects are equal and 1 if this object is bigger.

Specified by:
compareTo in interface Comparable<RelativeTime>
Parameters:
o - the object to compare with
Returns:
one of the values -1, 0, 1

absolute

public AbsoluteTime absolute(Clock clock)
Description copied from class: HighResolutionTime
Convert the time of this to an absolute time, using the given instance of Clock to determine the current time when necessary. If clock is null the real-time clock is assumed. A destination object is allocated to return the result. The clock association of the result is with the clock passed as a parameter. See the derived class comments for more specific information.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The instance of Clock used to convert the time of this into absolute time, and the new clock association for the result.
Returns:
The AbsoluteTime conversion in a newly allocated object, associated with the clock parameter.

absolute

public AbsoluteTime absolute(Clock clock,
                             AbsoluteTime dest)
Description copied from class: HighResolutionTime
Convert the time of this to an absolute time, using the given instance of Clock to determine the current time when necessary. If clock is null the real-time clock is assumed. If dest is not null, the result is placed there and returned. Otherwise, a new object is allocated for the result. The clock association of the result is with the clock passed as a parameter. See the derived class comments for more specific information.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The instance of Clock used to convert the time of this into absolute time, and the new clock association for the result.
dest - If dest is not null, the result is placed there and returned. Otherwise, a new object is allocated for the result.
Returns:
The AbsoluteTime conversion in dest if dest is not null, otherwise the result is returned in a newly allocated object. It is associated with the clock parameter.

add

public RelativeTime add(long millis,
                        int nanos)

add

public RelativeTime add(long millis,
                        int nanos,
                        RelativeTime dest)

add

public RelativeTime add(RelativeTime time)

add

public RelativeTime add(RelativeTime time,
                        RelativeTime dest)

addInterarrivalTo

public void addInterarrivalTo(AbsoluteTime timeAndDestination)

getInterarrivalTime

public RelativeTime getInterarrivalTime()

getInterarrivalTime

public RelativeTime getInterarrivalTime(RelativeTime destination)

relative

public RelativeTime relative(Clock clock)
Description copied from class: HighResolutionTime
Convert the time of this to a relative time, using the given instance of Clock to determine the current time when necessary. If clock is null the real-time clock is assumed. A destination object is allocated to return the result. The clock association of the result is with the clock passed as a parameter. See the derived class comments for more specific information.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The instance of Clock used to convert the time of this into relative time, and the new clock association for the result.
Returns:
The RelativeTime conversion in a newly allocated object, associated with the clock parameter.

relative

public RelativeTime relative(Clock clock,
                             RelativeTime dest)
Description copied from class: HighResolutionTime
Convert the time of this to a relative time, using the given instance of Clock to determine the current time when necessary. If clock is null the real-time clock is assumed. If dest is not null, the result is placed there and returned. Otherwise, a new object is allocated for the result. The clock association of the result is with the clock passed as a parameter. See the derived class comments for more specific information.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The instance of Clock used to convert the time of this into relative time, and the new clock association for the result.
dest - If dest is not null, the result is placed there and returned. Otherwise, a new object is allocated for the result.
Returns:
The RelativeTime conversion in dest if dest is not null, otherwise the result is returned in a newly allocated object. It is associated with the clock parameter.

subtract

public RelativeTime subtract(RelativeTime time)

subtract

public RelativeTime subtract(RelativeTime time,
                             RelativeTime dest)

toString

public String toString()
Overrides:
toString in class Object