javax.realtime
Class AbsoluteTime

java.lang.Object
  extended byjavax.realtime.HighResolutionTime
      extended byjavax.realtime.AbsoluteTime
All Implemented Interfaces:
Cloneable, Comparable

public class AbsoluteTime
extends HighResolutionTime

An object that represents a specific point in time given by milliseconds plus nanoseconds past the epoch (January 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 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, Morgan Deters

Constructor Summary
AbsoluteTime()
          Equal to new AbsoluteTime(0,0).
AbsoluteTime(AbsoluteTime time)
          Make a new AbsoluteTime object from the given AbsoluteTime object.
AbsoluteTime(AbsoluteTime time, Clock clock)
          Make a new AbsoluteTime object from the given AbsoluteTime object.
AbsoluteTime(Clock clock)
          Make a new AbsoluteTime object with an association to the given Clock.
AbsoluteTime(Date date)
          Equivalent to new AbsoluteTime (date.getTime(),0)
AbsoluteTime(Date date, Clock clock)
          Equivalent to AbsoluteTime(date.getTime(),0,clock).
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.
AbsoluteTime(long millis, int nanos, Clock clock)
          Construct an AbsoluteTime object which means a time millis milliseconds plus nanos nanoseconds past 00:00:00 GMT on January 1, 1970.
 
Method Summary
 AbsoluteTime absolute(Clock clock)
          Convert to absolute time (with respect to a given clock).
 AbsoluteTime absolute(Clock clock, AbsoluteTime dest)
          Convert to absolute time (with respect to a given clock).
 AbsoluteTime add(long millis, int nanos)
          Add millis and nanos to this.
 void add(long millis, int nanos, AbsoluteTime dest)
          If a destination is non-null, the result is placed there and the destination is returned.
 AbsoluteTime add(RelativeTime time)
          Return this + time.
 void add(RelativeTime time, AbsoluteTime destination)
          Return this + time, into the provided destination.
 void decrement(RelativeTime time)
          Increment this time by a given amount.
 Date getDate()
          Returns this time as a Date.
 void increment(RelativeTime time)
          Increments this time, by a given ammount.
 RelativeTime relative(Clock clock)
          Convert to relative time (with respect to a given clock).
 RelativeTime relative(Clock clock, RelativeTime dest)
          Convert to relative time (with respect to a given clock).
 RelativeTime subtract(AbsoluteTime time)
          Computes the difference (this - time).
 void subtract(AbsoluteTime time, RelativeTime destination)
          Computes the difference (this - time).
 AbsoluteTime subtract(RelativeTime time)
          Computes the difference (this - time).
 void subtract(RelativeTime time, AbsoluteTime dest)
          Computes the difference (this - time).
 String toString()
          Return a printable version of this time, in a format that matches java.util.Date.toString() with a postfix to the detail the sub-second value.
 
Methods inherited from class javax.realtime.HighResolutionTime
clone, compareTo, compareTo, equals, equals, getClock, getMilliseconds, getNanoseconds, hashCode, set, set, set, waitForObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbsoluteTime

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


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. Associate with the realtime Clock.

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

AbsoluteTime

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

Parameters:
millis - the milliseconds component of the elapsed time since the epoch
nanos - the nanosecond component of the elapsed time since the epoch
clock - the Clock to associate with this

AbsoluteTime

public AbsoluteTime(AbsoluteTime time)
Make a new AbsoluteTime object from the given AbsoluteTime object.

Parameters:
time - The AbsoluteTime object as the source for the copy.

AbsoluteTime

public AbsoluteTime(AbsoluteTime time,
                    Clock clock)
Make a new AbsoluteTime object from the given AbsoluteTime object.

Parameters:
time - The AbsoluteTime object as the source for the copy.

AbsoluteTime

public AbsoluteTime(Clock clock)
Make a new AbsoluteTime object with an association to the given Clock. Equivalent to AbsoluteTime(0,0,clock).

Parameters:
clock - the Clock to associate to this

AbsoluteTime

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

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

AbsoluteTime

public AbsoluteTime(Date date,
                    Clock clock)
Equivalent to AbsoluteTime(date.getTime(),0,clock).

Parameters:
date - the Date representation of the time past the epoch
clock - the Clock to associate to this
Method Detail

absolute

public AbsoluteTime absolute(Clock clock)
Convert to absolute time (with respect to a given clock). This implementation just returns this, since it is already an absolute time.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - the clock that will convert the time
Returns:
this

absolute

public AbsoluteTime absolute(Clock clock,
                             AbsoluteTime dest)
Convert to absolute time (with respect to a given clock). This implementation just sets dest to equal this, and returns dest.

Specified by:
absolute in class HighResolutionTime
Parameters:
clock - the clock that will convert the time
dest - the destination object
Returns:
a newly allocated AbsoluteTime if dest is null, otherwise dest

relative

public RelativeTime relative(Clock clock)
Convert to relative time (with respect to a given clock). Will allocate a destination object if necessary.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - the clock that will convert the time
Returns:
the new time, or this (if already a relative time)

relative

public RelativeTime relative(Clock clock,
                             RelativeTime dest)
Convert to relative time (with respect to a given clock). Will allocate a destination object if necessary.

Specified by:
relative in class HighResolutionTime
Parameters:
clock - the clock that will convert the time
dest - the destination object
Returns:
a newly allocated RelativeTime if dest is null, otherwise dest

add

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

Parameters:
millis - the milliseconds value to be added to this.
nanos - the nanoseconds value to be added to this.
Returns:
the result after adding this with millis and nanos.

add

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

Parameters:
millis - milliseconds
nanos - nanoseconds
dest - the destination that will hold the addition

add

public final AbsoluteTime add(RelativeTime time)
Return this + time. A new object is allocated for the result.

Parameters:
time - the time to add to this.
Returns:
the resulting sum

add

public final void add(RelativeTime time,
                      AbsoluteTime destination)
Return this + time, into the provided destination.

Parameters:
time - the time toa dd to this.
destination - the destination where to place the result.

increment

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

Parameters:
time - a RelativeTime value

decrement

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

Parameters:
time - a RelativeTime value

getDate

public Date getDate()
Returns this time as a Date.

Returns:
The time past the epoch represented by this as a Date

subtract

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

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

subtract

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

Parameters:
time - absolute time to subtract from this.
destination - the destination that will hold the result of the difference.

subtract

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

Parameters:
time - relative time to subtract from this
Returns:
a newly allocated object that holds the result of the difference.

subtract

public final void subtract(RelativeTime time,
                           AbsoluteTime dest)
Computes the difference (this - time).

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

toString

public String toString()
Return a printable version of this time, in a format that matches java.util.Date.toString() with a postfix to the detail the sub-second value.

Returns:
String object converted from this.


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