public class RelativeTime extends HighResolutionTime<RelativeTime>
The time interval is kept in normalized form. The range goes from [(-263) milliseconds + (-106+1) nanoseconds] to [(263-1) milliseconds + (106-1) nanoseconds].
A negative interval relative to now represents time in the past.
For add
and subtract
, negative values behave
as they do in arithmetic.
Caution: This class is explicitly unsafe for multithreading when being changed. Code that mutates instances of this class should synchronize at a higher level.
Constructor and Description |
---|
RelativeTime()
Equivalent to
RelativeTime(long, int, Chronograph) with argument
list (0, 0, null) . |
RelativeTime(Chronograph chronograph)
Equivalent to
RelativeTime(long, int, Chronograph) with argument
list (0, 0, chronograph) . |
RelativeTime(Clock clock)
Deprecated.
since version 2.0
|
RelativeTime(long millis,
int nanos)
Equivalent to
RelativeTime(long, int, Chronograph) with argument
list (millis, nanos, null) . |
RelativeTime(long millis,
int nanos,
Chronograph chronograph)
Constructs a
RelativeTime object representing an
interval based on the parameter millis plus the
parameter nanos . |
RelativeTime(long millis,
int nanos,
Clock clock)
Deprecated.
since version 2.0
|
RelativeTime(RelativeTime time)
Equivalent to
RelativeTime(long, int, Chronograph) with argument
list (time.getMilliseconds(), time.getNanoseconds(),
time.getChronograph()) . |
RelativeTime(RelativeTime time,
Chronograph chronograph)
Equivalent to
RelativeTime(long, int, Chronograph) with argument
list (time.getMilliseconds(), time.getNanoseconds(),
time.getChronograph()) . |
RelativeTime(RelativeTime time,
Clock clock)
Deprecated.
since version 2.0
|
Modifier and Type | Method and Description |
---|---|
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. |
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. |
AbsoluteTime |
absolute(Clock clock)
Deprecated.
since version 2.0
|
AbsoluteTime |
absolute(Clock clock,
AbsoluteTime dest)
Deprecated.
since version 2.0
|
RelativeTime |
add(long millis,
int nanos)
Creates a new object representing the result of adding
millis and nanos to the values from
this and normalizing the result. |
RelativeTime |
add(long millis,
int nanos,
RelativeTime dest)
Returns an object containing the value resulting from adding
millis and nanos to
the values from this and normalizing the result. |
RelativeTime |
add(RelativeTime time)
Creates a new instance of
RelativeTime
representing the result of adding time to
the value of this and normalizing the result. |
RelativeTime |
add(RelativeTime time,
RelativeTime dest)
Returns an object containing the value resulting from adding
time to the value of this and normalizing
the result. |
void |
addInterarrivalTo(AbsoluteTime timeAndDestination)
Deprecated.
|
RelativeTime |
apportion(int factor)
multiply the current time by an integral scaling factor.
|
RelativeTime |
apportion(int factor,
RelativeTime destination)
Divide the current time by an integral factor.
|
int |
compareToZero()
Compares
this to relative time zero returning the
result of the comparison. |
RelativeTime |
getInterarrivalTime()
Deprecated.
|
RelativeTime |
getInterarrivalTime(RelativeTime destination)
Deprecated.
|
RelativeTime |
multiply(float factor,
RelativeTime dest)
Multiply this relative time by a floating point factor.
|
RelativeTime |
negate()
Multiply the current time by -1.
|
RelativeTime |
negate(RelativeTime destination)
Multiply the current time by -1.
|
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. |
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. |
RelativeTime |
relative(Clock clock)
Deprecated.
since version 2.0
|
RelativeTime |
relative(Clock clock,
RelativeTime dest)
Deprecated.
since version 2.0
|
RelativeTime |
scale(int factor)
Changes the length of this relative time by multiplying it by
factor . |
RelativeTime |
scale(int factor,
RelativeTime time)
Sets
time to the value of this time multiplied
by factor . |
RelativeTime |
subtract(RelativeTime time)
Creates a new instance of
RelativeTime
representing the result of subtracting time from
the value of this
and normalizing the result. |
RelativeTime |
subtract(RelativeTime time,
RelativeTime dest)
Returns an object containing the value
resulting from subtracting the value of
time from
the value of this
and normalizing the result. |
java.lang.String |
toString()
Creates a printable string of the time given by
this . |
clone, compareTo, equals, equals, getChronograph, getClock, getMilliseconds, getNanoseconds, hashCode, set, set, set, set, waitForObject
public RelativeTime(long millis, int nanos, Chronograph chronograph) throws StaticIllegalArgumentException
RelativeTime
object representing an
interval based on the parameter millis
plus the
parameter nanos
. The construction is subject to
millis
and nanos
parameter
normalization. When there is an overflow in the millisecond
component when normalizing then an
StaticIllegalArgumentException
will be thrown.
The chronograph association is made with the chronograph
parameter.
When chronograph
is null
the association is made with
the default realtime clock.
millis
- The desired value for the millisecond component
of this
.
The actual value is the result of parameter normalization.nanos
- The desired value for the nanosecond component
of this
.
The actual value is the result of parameter normalization.chronograph
- The time reference of the newly
constructed object. Defaults to the realtime clock when null
.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.public RelativeTime(long millis, int nanos) throws StaticIllegalArgumentException
RelativeTime(long, int, Chronograph)
with argument
list (millis, nanos, null)
.millis
- The desired value for the millisecond component of
this
. The actual value is the result of
parameter normalization.nanos
- The desired value for the nanosecond component of
this
. The actual value is the result of
parameter normalization.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.public RelativeTime(RelativeTime time)
RelativeTime(long, int, Chronograph)
with argument
list (time.getMilliseconds(), time.getNanoseconds(),
time.getChronograph())
.time
- The RelativeTime
object which is the
source for the copy.public RelativeTime(RelativeTime time, Chronograph chronograph)
RelativeTime(long, int, Chronograph)
with argument
list (time.getMilliseconds(), time.getNanoseconds(),
time.getChronograph())
.time
- The RelativeTime
object which is the
source for the copy.public RelativeTime(Chronograph chronograph)
RelativeTime(long, int, Chronograph)
with argument
list (0, 0, chronograph)
.chronograph
- The time reference for the newly
constructed object.public RelativeTime()
RelativeTime(long, int, Chronograph)
with argument
list (0, 0, null)
.@Deprecated public RelativeTime(long millis, int nanos, Clock clock) throws StaticIllegalArgumentException
RelativeTime
object representing an
interval based on the parameter millis
plus the
parameter nanos
. The construction is subject to
millis
and nanos
parameter
normalization. When there is an overflow in the millisecond
component when normalizing then an
StaticIllegalArgumentException
will be thrown.
The clock association is made with the clock
parameter.
When clock
is null
the association is made with
the default realtime clock.
millis
- The desired value for the millisecond component
of this
.
The actual value is the result of parameter normalization.nanos
- The desired value for the nanosecond component
of this
.
The actual value is the result of parameter normalization.clock
- The clock providing the association for the newly
constructed object.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.@Deprecated public RelativeTime(RelativeTime time, Clock clock) throws StaticIllegalArgumentException
RelativeTime
object from the given
RelativeTime
object.
The clock association is made with the clock
parameter.
When clock
is null
the association is made with
the default realtime clock.
time
- The RelativeTime
object which is the
source for the copy.clock
- The clock providing the association for the newly
constructed object.StaticIllegalArgumentException
- when the time
parameter is null
.@Deprecated public RelativeTime(Clock clock)
new RelativeTime(0,0,clock)
.
The clock association is made with the clock
parameter.
When clock
is null
the association is made with
the default realtime clock.
clock
- The clock providing the association for the newly
constructed object.public AbsoluteTime absolute(Chronograph chronograph)
HighResolutionTime
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.
absolute
in class HighResolutionTime<RelativeTime>
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.HighResolutionTime.absolute(Chronograph)
public AbsoluteTime absolute(Chronograph chronograph, AbsoluteTime dest)
HighResolutionTime
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.absolute
in class HighResolutionTime<RelativeTime>
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.HighResolutionTime.absolute(Chronograph, AbsoluteTime)
public RelativeTime relative(Chronograph chronograph)
HighResolutionTime
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.relative
in class HighResolutionTime<RelativeTime>
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.HighResolutionTime.relative(Chronograph)
public RelativeTime relative(Chronograph chronograph, RelativeTime dest)
HighResolutionTime
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.relative
in class HighResolutionTime<RelativeTime>
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.HighResolutionTime.relative(Chronograph, RelativeTime)
public RelativeTime add(long millis, int nanos) throws java.lang.ArithmeticException
millis
and nanos
to the values from
this
and normalizing the result.
The result will have the same chronograph association as this
.
An ArithmeticException
is when the result does not
fit in the normalized format.millis
- The number of milliseconds to be added
to this
.nanos
- The number of nanoseconds to be added
to this
.RelativeTime
object whose time is
the normalization of this
plus millis
and nanos
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime add(long millis, int nanos, RelativeTime dest) throws java.lang.ArithmeticException
millis
and nanos
to
the values from this
and normalizing the result.
When dest
is not null
, the result is placed
there and returned. Otherwise, a new object is allocated for the result.
The result will have the same chronograph association as this
,
and the chronograph association with dest
is ignored.millis
- The number of milliseconds to be added
to this
.nanos
- The number of nanoseconds to be added
to this
.dest
- When dest
is not null
,
the result is placed there and returned.this
plus millis
and nanos
in
dest
when dest
is not null
,
otherwise the result is returned in a newly allocated object.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime add(RelativeTime time) throws StaticIllegalArgumentException, java.lang.ArithmeticException
RelativeTime
representing the result of adding time
to
the value of this
and normalizing the result.
The chronograph associated with
this
and the clock
associated with the time
parameter
are expected to be the same, and such association
is used for the result.
time
- The time to add to this
.RelativeTime
object whose time is the
normalization of this
plus the parameter
time
.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the
Chronograph
associated with the time
parameter are different, or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime add(RelativeTime time, RelativeTime dest) throws StaticIllegalArgumentException, java.lang.ArithmeticException
time
to the value of this
and normalizing
the result. When dest
is not null
, the
result is placed there and returned. Otherwise, a new object is
allocated for the result.
The Chronograph
associated with this
and
the Chronograph
associated with the time
parameter are expected to be the same, and such association is used
for the result.
The Chronograph
associated with the dest
parameter is ignored.
time
- The time to add to this
.dest
- When dest
is not null
, the
result is placed there and returned.this
plus
the RelativeTime
parameter time
in dest
when dest
is not
null
, otherwise the result is returned in a
newly allocated object.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the
Chronograph
associated with the time
parameter are different, or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime subtract(RelativeTime time) throws StaticIllegalArgumentException, java.lang.ArithmeticException
RelativeTime
representing the result of subtracting time
from
the value of this
and normalizing the result.
The Chronograph
associated with
this
and the Chronograph
associated with the time
parameter
are expected to be the same, and such association
is used for the result.
time
- The time to subtract from this
.RelativeTime
object whose time is the
normalization of this
minus the parameter
time
.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the
Chronograph
associated with the time
parameter are different, or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime subtract(RelativeTime time, RelativeTime dest) throws StaticIllegalArgumentException, java.lang.ArithmeticException
time
from
the value of this
and normalizing the result.
When dest
is not null
, the result is placed
there and returned. Otherwise, a new object is allocated for the result.
The Chronograph
associated with
this
and the Chronograph
associated with the time
parameter
are expected to be the same, and such association
is used for the result.
The Chronograph
associated with the dest
parameter
is ignored.
time
- The time to subtract from this
.dest
- When dest
is not null
, the
result is placed there and returned. Otherwise, a new object is
allocated for the result.this
minus
the RelativeTime
parameter time
in
dest
when dest
is not null
,
otherwise the result is returned in a newly allocated object.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the
Chronograph
associated with the time
parameter are different, or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime scale(int factor)
factor
.factor
- Value by which to increase the time interval.value
of this scaled by
factor
.public RelativeTime scale(int factor, RelativeTime time)
time
to the value of this
time multiplied
by factor
.factor
- Value by which to increase the time in this
.time
- Where to store the result.time
with the value of this
scaled by
factor
public RelativeTime apportion(int factor, RelativeTime destination)
factor
- by which to divide this time, which must be greater
than zero.destination
- the destination relative time object.StaticIllegalArgumentException
- when factor
is
zero or negative.public RelativeTime apportion(int factor)
factor
- by which to apportion this time.java.lang.ArithmeticException
- when the scaling results in an overflow.public RelativeTime multiply(float factor, RelativeTime dest)
factor
- the factor by which to multiply.dest
- an object into which to place the result.dest
, when not null
, or a new object
holding the result.public RelativeTime negate(RelativeTime destination)
scale(int, RelativeTime)
, where scale is given as -1; however
it is much faster.destination
- the destination relative time object.java.lang.ArithmeticException
- when the negation results in an overflow.public RelativeTime negate()
scale(int)
, where scale is given as -1; however
it is much faster.java.lang.ArithmeticException
- when the negation results in an overflow.public int compareToZero()
this
to relative time zero returning the
result of the comparison. Equivalent to constantZero.compareTo(this)this
is less than zero, 0, when it is equal
to zero and a positive when this
is greater than zero.public java.lang.String toString()
this
.
The string shall be a decimal representation of the milliseconds and nanosecond values; formatted as follows "(2251 ms, 750000 ns)"
toString
in class java.lang.Object
this
.@Deprecated public AbsoluteTime absolute(Clock clock) throws java.lang.ArithmeticException
this
to an absolute time, using the
given instance of Clock
to determine the current time.
The calculation is the current time indicated by the given instance of
Clock
plus the interval given by this
.
When clock
is null
the
realtime clock is assumed.
A destination object is allocated for the result.
The clock association of the result is with
the clock
passed as a parameter.absolute
in class HighResolutionTime<RelativeTime>
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.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.@Deprecated public AbsoluteTime absolute(Clock clock, AbsoluteTime dest) throws java.lang.ArithmeticException
this
to an absolute time, using the given
instance of Clock
to determine the current time. The calculation
is the current time indicated by the given instance of Clock
plus the interval given by this
. When clock is null
the
default realtime clock is assumed. When dest
is null
, a
destination object is allocated for the result. The clock association of
the result is with the clock
passed as a parameter.absolute
in class HighResolutionTime<RelativeTime>
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 there and returned.AbsoluteTime
conversion in
dest
when dest
is not null
,
otherwise the result is returned in a newly allocated object.
The result is associated with the clock
parameter.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.@Deprecated public RelativeTime relative(Clock clock)
this
. A new object is allocated for
the result. This method is the implementation of the
abstract
method of the HighResolutionTime
base class. No conversion into RelativeTime
is needed
in this case.
The clock association of the result is with the clock
passed as a parameter. When clock
is null
the association is made with the realtime clock.relative
in class HighResolutionTime<RelativeTime>
clock
- The clock
parameter is used only as the
new clock association with the result, since no conversion
is needed.this
in a newly allocated
RelativeTime
object, associated with the
clock
parameter.@Deprecated public RelativeTime relative(Clock clock, RelativeTime dest)
this
. When dest
is not
null
, the result is placed there and
returned. Otherwise, a new object is allocated for the result.
This method is the implementation of the abstract
method of the HighResolutionTime
base class. No
conversion into RelativeTime
is needed in this case.
The clock association of the result is with the clock
passed as a parameter. When clock
is null
the association is made with the realtime clock.relative
in class HighResolutionTime<RelativeTime>
clock
- The clock
parameter is used only as the
new clock association with the result, since no conversion
is needed.dest
- When dest
is not null
, the
result is placed there and returned.this
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 void addInterarrivalTo(AbsoluteTime timeAndDestination)
@Deprecated public RelativeTime getInterarrivalTime()
@Deprecated public RelativeTime getInterarrivalTime(RelativeTime destination)