Serializablepublic class Duration extends Object implements Serializable
Serializable duration of time.
Although this class is not declared final, it is not intended for extension. The behavior is undefined when subclasses are created and used.
ExpiryPolicy,
Serialized Form| Modifier and Type | Field | Description |
|---|---|---|
static Duration |
ETERNAL |
ETERNAL (forever).
|
static Duration |
FIVE_MINUTES |
Five minutes.
|
static Duration |
ONE_DAY |
One day.
|
static Duration |
ONE_HOUR |
One hour.
|
static Duration |
ONE_MINUTE |
One minute.
|
static long |
serialVersionUID |
The serialVersionUID required for
Serializable. |
static Duration |
TEN_MINUTES |
Ten minutes.
|
static Duration |
THIRTY_MINUTES |
Thirty minutes.
|
static Duration |
TWENTY_MINUTES |
Twenty minutes.
|
static Duration |
ZERO |
Zero (no time).
|
| Constructor | Description |
|---|---|
Duration() |
Constructs an eternal duration (
isEternal() is true). |
Duration(long startTime,
long endTime) |
Constructs a
Duration based on the duration between two
specified points in time (since the Epoc), measured in milliseconds. |
Duration(TimeUnit timeUnit,
long durationAmount) |
Constructs a duration.
|
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals(Object other) |
|
long |
getAdjustedTime(long time) |
Calculates the adjusted time (represented in milliseconds from the Epoc)
given a specified time in milliseconds (to be adjusted) by the duration.
|
long |
getDurationAmount() |
Obtain the number of TimeUnits in the Duration
|
TimeUnit |
getTimeUnit() |
Obtain the TimeUnit for the Duration
|
int |
hashCode() |
|
boolean |
isEternal() |
Determines if a
Duration is eternal (forever). |
boolean |
isZero() |
Determines if a
Duration is zero. |
public static final long serialVersionUID
Serializable.public static final Duration ETERNAL
public static final Duration ONE_DAY
public static final Duration ONE_HOUR
public static final Duration THIRTY_MINUTES
public static final Duration TWENTY_MINUTES
public static final Duration TEN_MINUTES
public static final Duration FIVE_MINUTES
public static final Duration ONE_MINUTE
public static final Duration ZERO
public Duration()
isEternal() is true). Since the duration is immutable
the constant ETERNAL should be used alternatively.public Duration(TimeUnit timeUnit, long durationAmount)
isEternal() is true) is represented by
specifying null for timeUnit and 0 for durationAmount.timeUnit - the unit of time to specify time in. The minimum time unit is milliseconds.durationAmount - how long, in the specified units, the cache entries should live.NullPointerException - if timeUnit is null and the durationAmount is not 0IllegalArgumentException - if durationAmount is less than 0 or a TimeUnit less than milliseconds is specifiedpublic Duration(long startTime,
long endTime)
Duration based on the duration between two
specified points in time (since the Epoc), measured in milliseconds.
If either parameter is Long.MAX_VALUE an eternal duration (isEternal()
is true) will be constructed.
startTime - the start time (since the Epoc)endTime - the end time (since the Epoc)public TimeUnit getTimeUnit()
public long getDurationAmount()
public boolean isEternal()
Duration is eternal (forever).Duration is eternalpublic boolean isZero()
Duration is zero.Duration is zeropublic long getAdjustedTime(long time)
If this instance represents an eternal duration (isEternal()
is true), the value Long.MAX_VALUE is returned.
time - the time from which to adjust given the durationCopyright © 2017. All rights reserved.