T
- is the type of high resolution time.public abstract class HighResolutionTime<T extends HighResolutionTime<T>> extends Object implements Comparable<T>, 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(Clock clock)
absolute converts this time to an absolute time relative to the
given clock.
|
abstract AbsoluteTime |
absolute(Clock clock,
AbsoluteTime dest)
absolute converts this time to an absolute time relative to the
given clock.
|
Object |
clone()
produces a clone of this object.
|
int |
compareTo(T time)
Compares
this HighResolutionTime with the specified HighResolutionTime time . |
boolean |
equals(Object object)
equals checks if this and object are equal.
|
boolean |
equals(T time)
equals checks if this and time are equal.
|
Clock |
getClock()
getClock returns a reference to the clock associated with this.
|
long |
getMilliseconds()
getMilliseconds returns the milliseconds part of this time
object.
|
int |
getNanoseconds()
getNanoseconds returns the nanoseconds part of this time
object.The time represented by this is
getMilliseconds()*1000000+ getNanosecondes() ns.
|
int |
hashCode()
hashCode calculates a hashCode for this.
|
abstract RelativeTime |
relative(Clock clock)
relative returns a new relative time object for this relative to
the given clock.
|
abstract RelativeTime |
relative(Clock clock,
RelativeTime time)
relative converts this time to a relative time using the given
clock.
|
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(Object target,
HighResolutionTime<?> time)
waitForObject waits for the given object using a
HighResolutionTime as timeout.
|
public abstract AbsoluteTime absolute(Clock clock)
clock
- The clock the result should be relative to.public abstract AbsoluteTime absolute(Clock clock, AbsoluteTime dest)
clock
- The clock the result should be relative to.dest
- The preallocated AbsoluteTime object to hold the
result. May be null to indicate that a new object should be
allocated.public int compareTo(T time)
this
HighResolutionTime
with the specified HighResolutionTime
time
.compareTo
in interface Comparable<T extends HighResolutionTime<T>>
StaticIllegalArgumentException
- when the time
parameter is not
associated with the same chronograph as
this
, or when the time
parameter is null
.ClassCastException
- when the time
parameter is not of
the same class as this
.time
- To be compared with the time of this
.time
.public boolean equals(T time)
time
- another HighResulutionTime object.public boolean equals(Object object)
equals
in class Object
object
- another object.Object.hashCode()
,
HashMap
public Clock getClock()
ensure
(Result != null);
public final long getMilliseconds()
public final int getNanoseconds()
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
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.ClassCastException
- when the type of this
and the type
of the parameter time
are not the
same.StaticIllegalArgumentException
- when the parameter time
is null
.time
- The new value of this
this
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 T set(long millis, int nanos)
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.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component while normalizing.
result of parameter normalization.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 thethis
public static boolean waitForObject(Object target, HighResolutionTime<?> time) throws InterruptedException
InterruptedException
- when another thread caused this
thread to be interrupted during the wait.target
- the target object to wait for.time
- The timeout given as AbsoluteTime or RelativeTime.true
when the notify was received before the
timeout; false
otherwise.public abstract RelativeTime relative(Clock clock)
clock
- The clock the result should be relative to.public abstract RelativeTime relative(Clock clock, RelativeTime time)
clock
- The clock the result should be relative to.time
- The preallocated RelativeTime object to hold the
result. May be null to indicate that a new object should be
allocated.aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2019 aicas GmbH. All Rights Reserved.