javax.realtime
Class AbsoluteTime

java.lang.Object
  |
  +--javax.realtime.HighResolutionTime
        |
        +--javax.realtime.AbsoluteTime
All Implemented Interfaces:
java.lang.Comparable

public class AbsoluteTime
extends HighResolutionTime

An object that represents a specific point in time given by milliseconds plus nanoseconds past the epoch (Jenuary 1, 1970, 00:00:00 GMT). This representation was designed to be compatible with the standard Java representation of an absolute time in the java.util.Date class.

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 AbsoluteTime representing time before the epoch is given as a parameter to 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.


Field Summary
static javax.realtime.AbsoluteTime endOfDays
           
 
Fields inherited from class javax.realtime.HighResolutionTime
defaultClock
 
Constructor Summary
AbsoluteTime()
          Equal to new AbsoluteTime(0,0).
AbsoluteTime(javax.realtime.AbsoluteTime t)
          Make a new AbsoluteTime object from the given AbsoluteTime object.
AbsoluteTime(java.util.Date date)
          Equivalent to new AbsoluteTime(date.getTime(), 0).
AbsoluteTime(long millis, int nanos)
          Construct an AbsoluteTime object which means a time millis milliseconds plus nanos nanoseconds past 00:00:00 GMT on January 1, 1970.
 
Method Summary
 javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock)
          Convert time given by this to an absolute time relative to a given clock.
 javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock, javax.realtime.AbsoluteTime destination)
          Convert this time to an absolute time.
 javax.realtime.AbsoluteTime add(long millis, int nanos)
          Add millis and nanos to this.
 javax.realtime.AbsoluteTime add(long millis, int nanos, javax.realtime.AbsoluteTime destination)
          Add millis and nanos to this.
 javax.realtime.AbsoluteTime add(javax.realtime.RelativeTime time)
          Add the time given by the parameter to this.
 javax.realtime.AbsoluteTime add(javax.realtime.RelativeTime time, javax.realtime.AbsoluteTime destination)
          Add the time given by the parameter to this.
 java.util.Date getDate()
          Convert the time given by this to a java.utilDate format.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock)
          Create a RelativeTime object with current time given by this with reference to the parameter.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock, javax.realtime.AbsoluteTime destination)
          Create a RelativeTime object with current time given by this with reference to Clock parameter.
 javax.realtime.RelativeTime relative(javax.realtime.Clock clock, javax.realtime.HighResolutionTime time)
          Create a RelativeTime object with current time given by this with reference to Clock parameter.
 void set(java.util.Date d)
          Change the time represented by this to that given by the parameter.
 javax.realtime.RelativeTime subtract(javax.realtime.AbsoluteTime time)
          Finds the difference between the time given by this and the time given by the parameter.
 javax.realtime.RelativeTime subtract(javax.realtime.AbsoluteTime time, javax.realtime.RelativeTime destination)
          Finds the difference between the time given by this and the time given by the parameter.
 javax.realtime.AbsoluteTime subtract(javax.realtime.RelativeTime time)
          Finds the difference between the time given by this and the time given by the parameter.
 javax.realtime.AbsoluteTime subtract(javax.realtime.RelativeTime time, javax.realtime.AbsoluteTime destination)
          Finds the difference between the time given by this and the time given by the parameter.
 java.lang.String toString()
          Create a printable string of the time given by this, in a format that matches java.util.Date.toString() with a postfix to the detail the nanosecond value.
 
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

endOfDays

public static javax.realtime.AbsoluteTime endOfDays
Constructor Detail

AbsoluteTime

public AbsoluteTime()
Equal to new AbsoluteTime(0,0).


AbsoluteTime

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


AbsoluteTime

public AbsoluteTime(java.util.Date date)
Equivalent to new AbsoluteTime(date.getTime(), 0).

Parameters:
date - The java.util.Date representation of the time past the epoch.

AbsoluteTime

public AbsoluteTime(long millis,
                    int nanos)
Construct an AbsoluteTime object which means a time millis milliseconds plus nanos nanoseconds past 00:00:00 GMT on January 1, 1970.

Parameters:
millis - The milliseconds component of the time past the epoch.
nanos - The nanosecond component of the time past the epoch.
Method Detail

absolute

public javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock)
Convert time given by this to an absolute time relative to a given clock.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The clock on which this will be based.
Returns:
A reference to this.

absolute

public javax.realtime.AbsoluteTime absolute(javax.realtime.Clock clock,
                                            javax.realtime.AbsoluteTime destination)
Convert this time to an absolute time. For an AbsoluteTime, this is really easy: it just return itself. Presumes that this is already relative to the given clock.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - The clock on which this is based.
destination - Converted to an absolute time.
Returns:
A reference to this.

add

public javax.realtime.AbsoluteTime add(long millis,
                                       int nanos)
Add millis and nanos to this. A new object is allocated for the result.

Parameters:
millis - The number of milliseconds to be added to this.
nanos - The number of nanoseconds to be added to this.
Returns:
A new AbsoluteTime object whose time is this plus millis and nanos.

add

public javax.realtime.AbsoluteTime add(long millis,
                                       int nanos,
                                       javax.realtime.AbsoluteTime destination)
Add millis and nanos to this. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result.

Parameters:
millis - The number of milliseconds to be added to this.
nanos - The number of nanoseconds to be added to this.
destination - A reference to an AbsoluteTime object into which the result of the addition may be placed.

add

public final javax.realtime.AbsoluteTime add(javax.realtime.RelativeTime time)
Add the time given by the parameter to this.

Parameters:
time - The time to add to this.
Returns:
A reference to this.

add

public javax.realtime.AbsoluteTime add(javax.realtime.RelativeTime time,
                                       javax.realtime.AbsoluteTime destination)
Add the time given by the parameter to this. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result.

Parameters:
time - The time to add to this.
destination - A reference to an AbsoluteTime object into which the result of the addition may be placed.
Returns:
A reference to destination or a new object whose time is this plus millisnano.

getDate

public java.util.Date getDate()
Convert the time given by this to a java.utilDate format. Note that java.util.Date represents time as milliseconds so the nanoseconds of this will be lost.

Returns:
A reference to a java.util.Date object with a value of the time past the epoch represented by this.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock)
Create a RelativeTime object with current time given by this with reference to the parameter.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The clock reference used as a reference for this.
Returns:
A reference to a new RelativeTime object whose time is set to the time given by this referencing the parameter.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock,
                                            javax.realtime.AbsoluteTime destination)
Create a RelativeTime object with current time given by this with reference to Clock parameter. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result

Parameters:
clock - The clock reference used as a reference for this.
destination - A reference to a RelativeTime object into which the result of the subtraction may be placed.
Returns:
A reference to a new RelativeTime object whose time is set to the time given by this referencing the parameter.

relative

public javax.realtime.RelativeTime relative(javax.realtime.Clock clock,
                                            javax.realtime.HighResolutionTime time)
Create a RelativeTime object with current time given by this with reference to Clock parameter. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result

Specified by:
relative in class HighResolutionTime
Parameters:
clock - The clock reference used as a reference for this.
time - A reference to a HighResolutionTime object into which the result of the subtraction may be placed.
Returns:
A reference to a new RelativeTime object whose time is set to the time given by this referencing the parameter.

set

public void set(java.util.Date d)
Change the time represented by this to that given by the parameter.


subtract

public final javax.realtime.RelativeTime subtract(javax.realtime.AbsoluteTime time)
Finds the difference between the time given by this and the time given by the parameter. The difference is, of course, a RelativeTime.

Parameters:
time - A reference to an AbsoluteTime object whose time is subtracted from this.
Returns:
A reference to a new RelativeTime object whose time is the difference.

subtract

public javax.realtime.RelativeTime subtract(javax.realtime.AbsoluteTime time,
                                            javax.realtime.RelativeTime destination)
Finds the difference between the time given by this and the time given by the parameter. The difference is, of course, a RelativeTime. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result.

Parameters:
time - A reference to an AbsoluteTime object whose time is subtracted from this.
destination - A reference to an RelativeTime object into which the result of the addition may be placed.
Returns:
A reference to a new RelativeTime object whose time is the difference between this and the time paramter.

subtract

public final javax.realtime.AbsoluteTime subtract(javax.realtime.RelativeTime time)
Finds the difference between the time given by this and the time given by the parameter.

Parameters:
time - A reference to an AbsoluteTime object whose time is subtracted from this.
Returns:
A reference to a new AbsoluteTime object whose time is the difference.

subtract

public javax.realtime.AbsoluteTime subtract(javax.realtime.RelativeTime time,
                                            javax.realtime.AbsoluteTime destination)
Finds the difference between the time given by this and the time given by the parameter. The difference is, of course, a RelativeTime. If the destination is non-null, the result is placed there and returned. Otherwise, a new object is allocated for the result.

Parameters:
time - A reference to an AbsoluteTime object whose time is subtracted from this.
destination - A reference to an AbsoluteTime object into which the result of the addition may be placed.
Returns:
A reference to a new AbsoluteTime object whose time is the difference between this and time parameter.

toString

public java.lang.String toString()
Create a printable string of the time given by this, in a format that matches java.util.Date.toString() with a postfix to the detail the nanosecond value.

Overrides:
toString in class java.lang.Object
Returns:
String object converted from the time given ty this.