@Extensibility(value=FINAL_EXTENSIBILITY) @Nested public abstract class Duration extends Object implements Comparable<Duration>, Serializable, DDSObject
Constructor and Description |
---|
Duration() |
Modifier and Type | Method and Description |
---|---|
abstract Duration |
add(Duration duration) |
abstract Duration |
add(long duration,
TimeUnit unit) |
abstract long |
getDuration(TimeUnit inThisUnit)
Truncate this duration to a whole-number quantity of the given time
unit.
|
abstract long |
getRemainder(TimeUnit primaryUnit,
TimeUnit remainderUnit)
If getting the magnitude of this duration in the given
primaryUnit would cause truncation with respect to the
given remainderUnit , return the magnitude of the
truncation in the latter (presumably finer-grained) unit. |
static Duration |
infiniteDuration(ServiceEnvironment env) |
abstract boolean |
isInfinite()
Report whether this duration lasts forever.
|
abstract boolean |
isZero()
Report whether this duration lasts no time at all.
|
static Duration |
newDuration(long duration,
TimeUnit unit,
ServiceEnvironment env)
Construct a time duration of the given magnitude.
|
abstract Duration |
subtract(Duration duration) |
abstract Duration |
subtract(long duration,
TimeUnit unit) |
static Duration |
zeroDuration(ServiceEnvironment env) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compareTo
getEnvironment
public static Duration newDuration(long duration, TimeUnit unit, ServiceEnvironment env)
Long.MAX_VALUE
indicates an infinite
duration, regardless of the units specified.env
- Identifies the Service instance to which the new
object will belong.isInfinite()
,
infiniteDuration(ServiceEnvironment)
public static Duration infiniteDuration(ServiceEnvironment env)
env
- Identifies the Service instance to which the
object will belong.Duration
of infinite length.public static Duration zeroDuration(ServiceEnvironment env)
env
- Identifies the Service instance to which the
object will belong.Duration
of zero length.public abstract long getDuration(TimeUnit inThisUnit)
TimeUnit.SECONDS
will result in the value 1
.
If this duration is infinite, this method shall return
Long.MAX_VALUE
, regardless of the units given.
If this duration cannot be expressed in the given units without
overflowing, this method shall return Long.MAX_VALUE
. In such
a case, the caller may wish to use this method in combination with
getRemainder(TimeUnit, TimeUnit)
to obtain the full duration
without lack of precision.inThisUnit
- The time unit in which the return result will
be measured.getRemainder(TimeUnit, TimeUnit)
,
Long.MAX_VALUE
,
TimeUnit
public abstract long getRemainder(TimeUnit primaryUnit, TimeUnit remainderUnit)
primaryUnit
would cause truncation with respect to the
given remainderUnit
, return the magnitude of the
truncation in the latter (presumably finer-grained) unit. For example,
if this duration is equal to one second plus 100 nanoseconds, calling
this method with arguments of TimeUnit.SECONDS
and
TimeUnit.NANOSECONDS
respectively will result in the value
100
.
This method is equivalent to the following pseudo-code:
(this - getDuration(primaryUnit)).getDuration(remainderUnit)
If remainderUnit
is represents a coarser granularity than
primaryUnit
(for example, the former is
TimeUnit.HOURS
but the latter is TimeUnit.SECONDS
),
this method shall return 0
.
If the resulting duration cannot be expressed in the given units
without overflowing, this method shall return Long.MAX_VALUE
.primaryUnit
- remainderUnit
- The time unit in which the return result will
be measured.getDuration(TimeUnit)
,
Long.MAX_VALUE
,
TimeUnit
public abstract boolean isZero()
this.getDuration(TimeUnit.NANOSECONDS) == 0;
getDuration(TimeUnit)
public abstract boolean isInfinite()
this.equals(infiniteDuration(this.getEnvironment()))
infiniteDuration(ServiceEnvironment)
public abstract Duration add(Duration duration)
public abstract Duration add(long duration, TimeUnit unit)
public abstract Duration subtract(Duration duration)
Copyright © 2014. All rights reserved.