Package javax.cache.expiry
Class Duration
java.lang.Object
javax.cache.expiry.Duration
- All Implemented Interfaces:
Serializable
A
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.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
How long, in the specified units, the cache entries should live.static final Duration
ETERNAL (forever).static final Duration
Five minutes.static final Duration
One day.static final Duration
One hour.static final Duration
One minute.static final long
The serialVersionUID required forSerializable
.static final Duration
Ten minutes.static final Duration
Thirty minutes.private final TimeUnit
The unit of time to specify time in.static final Duration
Twenty minutes.static final Duration
Zero (no time). -
Constructor Summary
ConstructorsConstructorDescriptionDuration()
Constructs an eternal duration (isEternal()
is true).Duration
(long startTime, long endTime) Constructs aDuration
based on the duration between two specified points in time (since the Epoc), measured in milliseconds.Constructs a duration. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Obtain the number of TimeUnits in the DurationObtain the TimeUnit for the Durationint
hashCode()
boolean
Determines if aDuration
is eternal (forever).boolean
isZero()
Determines if aDuration
is zero.
-
Field Details
-
serialVersionUID
public static final long serialVersionUIDThe serialVersionUID required forSerializable
.- See Also:
-
ETERNAL
ETERNAL (forever). -
ONE_DAY
One day. -
ONE_HOUR
One hour. -
THIRTY_MINUTES
Thirty minutes. -
TWENTY_MINUTES
Twenty minutes. -
TEN_MINUTES
Ten minutes. -
FIVE_MINUTES
Five minutes. -
ONE_MINUTE
One minute. -
ZERO
Zero (no time). -
timeUnit
The unit of time to specify time in. The minimum time unit is milliseconds. -
durationAmount
private final long durationAmountHow long, in the specified units, the cache entries should live. The lifetime is measured from the cache entry was last accessed or mutated.
-
-
Constructor Details
-
Duration
public Duration()Constructs an eternal duration (isEternal()
is true). Since the duration is immutable the constantETERNAL
should be used alternatively. -
Duration
Constructs a duration. The eternal duration (isEternal()
is true) is represented by specifyingnull
fortimeUnit
and0
fordurationAmount
.- Parameters:
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.- Throws:
NullPointerException
- if timeUnit is null and thedurationAmount
is not 0IllegalArgumentException
- if durationAmount is less than 0 or a TimeUnit less than milliseconds is specified
-
Duration
public Duration(long startTime, long endTime) Constructs aDuration
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.- Parameters:
startTime
- the start time (since the Epoc)endTime
- the end time (since the Epoc)
-
-
Method Details
-
getTimeUnit
Obtain the TimeUnit for the Duration- Returns:
- the TimeUnit
-
getDurationAmount
public long getDurationAmount()Obtain the number of TimeUnits in the Duration- Returns:
- the number of TimeUnits
-
isEternal
public boolean isEternal()Determines if aDuration
is eternal (forever).- Returns:
- true if the
Duration
is eternal
-
isZero
public boolean isZero()Determines if aDuration
is zero.- Returns:
- true if the
Duration
is zero
-
getAdjustedTime
public 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.If this instance represents an eternal duration (
isEternal()
is true), the valueLong.MAX_VALUE
is returned.- Parameters:
time
- the time from which to adjust given the duration- Returns:
- the adjusted time
-
equals
-
hashCode
public int hashCode()
-