javax.realtime
Class RelativeTime

java.lang.Object
  extended byjavax.realtime.HighResolutionTime
      extended byjavax.realtime.RelativeTime
All Implemented Interfaces:
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.

Author:
Angelo Corsaro

Field Summary
 
Fields inherited from class javax.realtime.HighResolutionTime
millis, nanos
 
Constructor Summary
RelativeTime()
          Equivalent to new RelativeTime(0,0).
RelativeTime(long millis, int nanos)
          Construct a new RelativeTime object from the given millisecond and nanosecond components.
RelativeTime(RelativeTime relativeTime)
          Construct a new RelativeTime object from the given RelativeTime.
 
Method Summary
 AbsoluteTime absolute(Clock clock)
          Convert this time to an absolute time, relative to some clock.
 void absolute(Clock clock, AbsoluteTime dest)
          Convert this time to an absolute time, relative to some clock.
 RelativeTime add(long millis, int nanos)
          Add a specific number of milli and nano seconds to this .
 void 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.
 void add(RelativeTime time, RelativeTime dest)
          Return this + time.
 void decrement(RelativeTime time)
          Increment this time by a given amount.
 void increment(RelativeTime time)
          Increments this time, by a given ammount.
 RelativeTime subtract(RelativeTime time)
          Computes the diffenrence (this - time).
 void subtract(RelativeTime time, RelativeTime destination)
          Computes the diffenrence (this - time).
 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 new RelativeTime object from the given millisecond and nanosecond components.

Parameters:
millis - a long value specifing the seconds components
nanos - an int value specifing the nano seconds componenet

RelativeTime

public RelativeTime(RelativeTime relativeTime)
Construct a new RelativeTime object from the given RelativeTime.

Parameters:
relativeTime - a RelativeTime value from which the time for this object will be taken
Method Detail

absolute

public AbsoluteTime absolute(Clock clock)
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.

Parameters:
clock - The clock is used to convert this time into absolute time.
Returns:
the computed absolute time.

absolute

public void absolute(Clock clock,
                     AbsoluteTime dest)
Convert this time to an absolute time, relative to some clock. Convenient for situations where you really need an absolute time.

Parameters:
clock - The clock is used to convert this time into absolute time.
dest - the destination for the computed absolute time.

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 sum of this and the time passed as argument.

add

public void add(RelativeTime time,
                RelativeTime dest)
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.
dest - where the result should be placed.

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 void add(long millis,
                int nanos,
                RelativeTime destination)
Add a specific number of milli and nano seconds to this.

Parameters:
millis - milli seconds to add.
nanos - nano seconds to add.
destination - the destination were to store the result.

subtract

public final RelativeTime subtract(RelativeTime time)
Computes the diffenrence (this - time).

Parameters:
time - relative time to subtract from this.
Returns:
The new object is allocated for the result.

subtract

public final void subtract(RelativeTime time,
                           RelativeTime destination)
Computes the diffenrence (this - time).

Parameters:
time - relative time to subtract from this.
destination - the destination object that will hold the result.

increment

public void increment(RelativeTime time)
Increments this time, by a given ammount.

Parameters:
time - the increment represented by a a RelativeTime value

decrement

public void decrement(RelativeTime time)
Increment this time by a given amount.

Parameters:
time - the decrement represented by a a RelativeTime value.

toString

public String toString()
Return a printable version of this time.

Returns:
String object converted from this.


jRate is developed and maintained by the jRate project development team.
Copyright (c) 2001-2005 Angelo Corsaro and Morgan Deters.