T
- is the type of high resolution time.public abstract class HighResolutionTime<T extends HighResolutionTime<T>>
extends java.lang.Object
implements java.lang.Comparable<T>, java.lang.Cloneable
HighResolutionTime
is the base class for
AbsoluteTime
and RelativeTime
. It can be
used to express time with nanosecond resolution. This class is never
used directly; it is abstract and has no public constructor.
Instead, one of its subclasses AbsoluteTime
or RelativeTime
should be used. When an API is defined that has a
HighResolutionTime
as a parameter, it can take either an
absolute or a relative time and will do something appropriate.Caution: This class is explicitly unsafe for multithreading when being changed. Code that mutates instances of this class should synchronize at a higher level.
Modifier and Type | Method and Description |
---|---|
abstract AbsoluteTime |
absolute(Chronograph chronograph)
Converts the time of
this to an absolute time, using the
given instance of Chronograph to determine the current time when
necessary. |
abstract AbsoluteTime |
absolute(Chronograph chronograph,
AbsoluteTime dest)
Converts the time of
this to an absolute time, using the
given instance of Chronograph to determine the current time when
necessary. |
abstract AbsoluteTime |
absolute(Clock clock)
Deprecated.
since version 2.0
|
abstract AbsoluteTime |
absolute(Clock clock,
AbsoluteTime dest)
Deprecated.
since version 2.0
|
java.lang.Object |
clone()
Returns a clone of
this . |
int |
compareTo(T time)
Compares
this HighResolutionTime
with the specified HighResolutionTime time . |
boolean |
equals(java.lang.Object object)
Determined whether or not the argument
object has the
same type and values as this . |
boolean |
equals(T time)
Proves if the argument
time
has the same type and values as this . |
Chronograph |
getChronograph()
Gets a reference to the
Chronograph associated with
this . |
Clock |
getClock()
Gets the reference to the
clock associated with
this . |
long |
getMilliseconds()
Gets the milliseconds component of
this . |
int |
getNanoseconds()
Gets the nanoseconds component of
this . |
int |
hashCode()
Returns a hash code for this object in accordance with the general
contract of
Object.hashCode . |
abstract RelativeTime |
relative(Chronograph chronograph)
Converts the time of
this to a relative time, using the
given instance of Chronograph to determine the current time when
necessary. |
abstract RelativeTime |
relative(Chronograph chronograph,
RelativeTime dest)
Converts the time of
this to a relative time, using the
given instance of Chronograph to determine the current time when
necessary. |
abstract RelativeTime |
relative(Clock clock)
Deprecated.
since version 2.0
|
abstract RelativeTime |
relative(Clock clock,
RelativeTime dest)
Deprecated.
since version 2.0
|
T |
set(Chronograph chronograph,
long millis,
int nanos)
Sets the all components of
this . |
T |
set(long millis)
Sets the millisecond component of
this to the given
argument, and the nanosecond component of
this to 0. |
T |
set(long millis,
int nanos)
Sets the millisecond and nanosecond components of
this . |
T |
set(T time)
Changes the value represented by
this to that of the
given time . |
static boolean |
waitForObject(java.lang.Object target,
HighResolutionTime<?> time)
Behaves like
target.wait() but with the
enhancement that it waits with a precision of
HighResolutionTime and returns true when the
associated notify was received, false when timeout occured. |
public static boolean waitForObject(java.lang.Object target, HighResolutionTime<?> time) throws java.lang.InterruptedException, java.lang.IllegalMonitorStateException, StaticIllegalArgumentException, StaticUnsupportedOperationException
target.wait()
but with the
enhancement that it waits with a precision of
HighResolutionTime
and returns true when the
associated notify was received, false when timeout occured.
As for target.wait()
, there is the
possibility of spurious wakeup behavior.
The wait time
may be relative or absolute,
and it is controlled by the clock
associated with it.
When the wait time
is relative, then the calling
thread is blocked waiting on target
for the amount of time given by time
,
and measured by the associated clock
.
When the wait time
is absolute, then the calling
thread is blocked waiting on target
until the indicated time
value
is reached by the associated clock
.
target
- The object for which to wait.
The current thread must have a lock on the object.time
- The time for which to wait. When it is
RelativeTime(0,0)
then wait indefinitely. When it is
null
then wait indefinitely.true
when the notify was received before the
timeout; false
otherwise.java.lang.InterruptedException
- when this schedulable is
interrupted by RealtimeThread.interrupt()
or
AsynchronouslyInterruptedException.fire()
while it is
waiting.StaticIllegalArgumentException
- when time
represents a relative time less than zero.java.lang.IllegalMonitorStateException
- when target
is not locked by the caller.StaticUnsupportedOperationException
- when the
wait operation is not supported
using the clock
associated with time
.public boolean equals(T time)
time
has the same type and values as this
.
Equality includes Chronograph
association.
time
- Value to be compared with this
.true
when the parameter time
is of the
same type and has the same values as this
, as well as the
same Chronograph
association.public Clock getClock() throws StaticUnsupportedOperationException
clock
associated with
this
.clock
associated with
this
.StaticUnsupportedOperationException
- when the time is based on a
Chronograph
that is not a Clock
.public final Chronograph getChronograph()
Chronograph
associated with
this
.Chronograph
associated with
this
.public final long getMilliseconds()
this
.this
.public final int getNanoseconds()
this
.this
.public T set(T time)
this
to that of the
given time
.
The Chronograph
associated with this
is set
to be the Chronograph
associated with
the time
parameter.time
- The new value for this
.this
StaticIllegalArgumentException
- when the parameter
time
is null
.java.lang.ClassCastException
- when the type of this
and the type of the parameter time
are not the same.public T set(Chronograph chronograph, long millis, int nanos) throws StaticIllegalArgumentException
this
.
The setting is subject to parameter normalization.
When after normalization the time is negative, the time represented by
this
is set to a negative value, but note, negative
times are not supported everywhere. For instance, a negative relative
time is an invalid value for a periodic thread's period.chronograph
- The time reference for the other components of
this
set during the call call.millis
- The desired value for the millisecond component of
this
at the completion of the call.
The actual value is the result of parameter normalization.nanos
- The desired value for the nanosecond component of
this
at the completion of the call.
The actual value is the result of parameter normalization.this
StaticIllegalArgumentException
- when there is an overflow in the
millisecond component while normalizing.public T set(long millis, int nanos) throws StaticIllegalArgumentException
this
.
The setting is subject to parameter normalization.
When after normalization the time is negative then the time represented by
this
is set to a negative value, but note that negative
times are not supported everywhere. For instance, a negative relative
time is an invalid value for a periodic thread's period.millis
- The desired value for the millisecond component of
this
at the completion of the call.
The actual value is the result of parameter normalization.nanos
- The desired value for the nanosecond component of
this
at the completion of the call.
The actual value is the result of parameter normalization.this
StaticIllegalArgumentException
- when there is an overflow in the
millisecond component while normalizing.public T set(long millis)
this
to the given
argument, and the nanosecond component of
this
to 0. This method is equivalent to
set(millis, 0)
.millis
- This value shall be the value of the millisecond
component of this
at the completion of the call.this
public int hashCode()
Object.hashCode
. Time objects that are
equal, as defined by equals(T)
, have the same hash code.hashCode
in class java.lang.Object
public java.lang.Object clone()
this
. This method should behave
effectively as when it constructed a new object with the visible
values of this
. The new object is created in the
current allocation context.clone
in class java.lang.Object
public int compareTo(T time)
this
HighResolutionTime
with the specified HighResolutionTime
time
.compareTo
in interface java.lang.Comparable<T extends HighResolutionTime<T>>
time
- To be compared with the time of this
.time
.java.lang.ClassCastException
- when the time
parameter is
not of the same class as this
.StaticIllegalArgumentException
- when the
time
parameter is
not associated with the same chronograph as this
, or when
the time
parameter is null
.public boolean equals(java.lang.Object object)
object
has the
same type and values as this
.
Equality includes
Chronograph
association.
equals
in class java.lang.Object
object
- Value to be compared with this
.true
when the parameter object
is of the same type and
has the same
values as this
, as well as the same Chronograph
association.public abstract AbsoluteTime absolute(Chronograph chronograph, AbsoluteTime dest)
this
to an absolute time, using the
given instance of Chronograph
to determine the current time when
necessary. When Chronograph
is null
the
default realtime clock is assumed.
When dest
is not null
, the result is placed
in it and returned. Otherwise, a new object is allocated for the result.
The chronograph association of the result is the Chronograph
passed as a parameter. See the subclass comments for more specific
information.chronograph
- The instance of Chronograph
used to convert the
time of this
into absolute time,
and the new chronograph association for the result.dest
- When dest
is not null
,
the result is placed in it and returned.AbsoluteTime
conversion in
dest
when dest
is not null
,
otherwise the result is returned in a newly allocated object.
It is associated with the Chronograph
parameter.public abstract AbsoluteTime absolute(Chronograph chronograph)
this
to an absolute time, using the
given instance of Chronograph
to determine the current time when
necessary. When Chronograph
is null
the
realtime clock is assumed.
A destination object is allocated to return the result.
The chronograph association of the result is the Chronograph
passed as a parameter. See the subclass comments for more specific
information.
chronograph
- The instance of Chronograph
used to convert
the time of this
into absolute time, and the new
chronograph association for the result.AbsoluteTime
conversion in a newly allocated
object, associated with the Chronograph
parameter.public abstract RelativeTime relative(Chronograph chronograph, RelativeTime dest)
this
to a relative time, using the
given instance of Chronograph
to determine the current time when
necessary. When Chronograph
is null
the
realtime clock is assumed.
When dest
is not null
, the result is placed
there and returned. Otherwise, a new object is allocated for the result.
The chronograph association of the result is the Chronograph
passed as a parameter. See the subclass comments for more specific
information.chronograph
- The instance of Chronograph
used to convert the
time of this
into relative time, and the new
chronograph association for the result.dest
- When dest
is not null
, the result
is placed in it and returned.RelativeTime
conversion in dest
when dest
is not null
, otherwise the
result is returned in a newly allocated object.public abstract RelativeTime relative(Chronograph chronograph)
this
to a relative time, using the
given instance of Chronograph
to determine the current time when
necessary. When Chronograph
is null
the
realtime clock is assumed.
A destination object is allocated to return the result.
The chronograph association of the result is
the Chronograph
passed as a parameter.
See the subclass comments for more specific information.chronograph
- The instance of Chronograph
used to convert the
time of this
into relative time, and the new chronograph
association for the result.RelativeTime
conversion in a newly allocated
object, associated with the Chronograph
parameter.@Deprecated public abstract AbsoluteTime absolute(Clock clock, AbsoluteTime dest)
absolute(Chronograph, AbsoluteTime)
.
When dest
is not null
, the result is placed
in it and returned. Otherwise, a new object is allocated for the result.
The clock association of the result is the clock
passed
as a parameter.
See the subclass comments for more specific information.clock
- The instance of Clock
used to convert the
time of this
into absolute time, and the new clock
association for the result.dest
- when dest
is not null
,
the result is placed it and returned.AbsoluteTime
conversion in dest
when
dest
is not null
, otherwise the result
is returned in a newly allocated object. It is associated with
the clock
parameter.@Deprecated public abstract AbsoluteTime absolute(Clock clock)
absolute(Chronograph)
.clock
- The instance of Clock
used to convert the
time of this
into absolute time, and the new clock
association for the result.AbsoluteTime
conversion in a newly allocated
object, associated with the clock
parameter.@Deprecated public abstract RelativeTime relative(Clock clock, RelativeTime dest)
relative(Chronograph, RelativeTime)
clock
- The instance of Clock
used to convert the
time of this
into relative time, and the new clock
association for the result.dest
- When dest
is not null
, the result
is placed in it and returned.RelativeTime
conversion in dest
when dest
is not null
, otherwise the
result is returned in a newly allocated object.@Deprecated public abstract RelativeTime relative(Clock clock)
relative(Chronograph)
clock
- The instance of Clock
used to convert the
time of this
into relative time, and the new clock
association for the result.RelativeTime
conversion in a newly allocated
object, associated with the clock
parameter.