Package javax.cache.expiry
Class Duration
- java.lang.Object
-
- javax.cache.expiry.Duration
-
- All Implemented Interfaces:
java.io.Serializable
public class Duration extends java.lang.Object implements java.io.SerializableASerializableduration 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:
ExpiryPolicy, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private longdurationAmountHow long, in the specified units, the cache entries should live.static DurationETERNALETERNAL (forever).static DurationFIVE_MINUTESFive minutes.static DurationONE_DAYOne day.static DurationONE_HOUROne hour.static DurationONE_MINUTEOne minute.static longserialVersionUIDThe serialVersionUID required forSerializable.static DurationTEN_MINUTESTen minutes.static DurationTHIRTY_MINUTESThirty minutes.private java.util.concurrent.TimeUnittimeUnitThe unit of time to specify time in.static DurationTWENTY_MINUTESTwenty minutes.static DurationZEROZero (no time).
-
Constructor Summary
Constructors Constructor Description Duration()Constructs an eternal duration (isEternal()is true).Duration(long startTime, long endTime)Constructs aDurationbased on the duration between two specified points in time (since the Epoc), measured in milliseconds.Duration(java.util.concurrent.TimeUnit timeUnit, long durationAmount)Constructs a duration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object other)longgetAdjustedTime(long time)Calculates the adjusted time (represented in milliseconds from the Epoc) given a specified time in milliseconds (to be adjusted) by the duration.longgetDurationAmount()Obtain the number of TimeUnits in the Durationjava.util.concurrent.TimeUnitgetTimeUnit()Obtain the TimeUnit for the DurationinthashCode()booleanisEternal()Determines if aDurationis eternal (forever).booleanisZero()Determines if aDurationis zero.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
The serialVersionUID required forSerializable.- See Also:
- Constant Field Values
-
ETERNAL
public static final Duration ETERNAL
ETERNAL (forever).
-
ONE_DAY
public static final Duration ONE_DAY
One day.
-
ONE_HOUR
public static final Duration ONE_HOUR
One hour.
-
THIRTY_MINUTES
public static final Duration THIRTY_MINUTES
Thirty minutes.
-
TWENTY_MINUTES
public static final Duration TWENTY_MINUTES
Twenty minutes.
-
TEN_MINUTES
public static final Duration TEN_MINUTES
Ten minutes.
-
FIVE_MINUTES
public static final Duration FIVE_MINUTES
Five minutes.
-
ONE_MINUTE
public static final Duration ONE_MINUTE
One minute.
-
ZERO
public static final Duration ZERO
Zero (no time).
-
timeUnit
private final java.util.concurrent.TimeUnit timeUnit
The unit of time to specify time in. The minimum time unit is milliseconds.
-
durationAmount
private final long durationAmount
How long, in the specified units, the cache entries should live. The lifetime is measured from the cache entry was last accessed or mutated.
-
-
Constructor Detail
-
Duration
public Duration()
Constructs an eternal duration (isEternal()is true). Since the duration is immutable the constantETERNALshould be used alternatively.
-
Duration
public Duration(java.util.concurrent.TimeUnit timeUnit, long durationAmount)Constructs a duration. The eternal duration (isEternal()is true) is represented by specifyingnullfortimeUnitand0fordurationAmount.- 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:
java.lang.NullPointerException- if timeUnit is null and thedurationAmountis not 0java.lang.IllegalArgumentException- if durationAmount is less than 0 or a TimeUnit less than milliseconds is specified
-
Duration
public Duration(long startTime, long endTime)Constructs aDurationbased on the duration between two specified points in time (since the Epoc), measured in milliseconds.If either parameter is
Long.MAX_VALUEan eternal duration (isEternal()is true) will be constructed.- Parameters:
startTime- the start time (since the Epoc)endTime- the end time (since the Epoc)
-
-
Method Detail
-
getTimeUnit
public java.util.concurrent.TimeUnit 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 aDurationis eternal (forever).- Returns:
- true if the
Durationis eternal
-
isZero
public boolean isZero()
Determines if aDurationis zero.- Returns:
- true if the
Durationis 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_VALUEis returned.- Parameters:
time- the time from which to adjust given the duration- Returns:
- the adjusted time
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-