Top Description Fields Constructors Methods
javax.cache.expiry

public Class Duration

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.concurrent.TimeUnit

A java.io.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.

Authors
Yannis Cosmadopoulos, Greg Luck, Brian Oliver
Since
1.0
See Also
ExpiryPolicy

Field Summary

Modifier and TypeField and Description
private final long
durationAmount

How long, in the specified units, the cache entries should live.

public static final Duration
ETERNAL

ETERNAL (forever).

public static final Duration
FIVE_MINUTES

Five minutes.

public static final Duration
ONE_DAY

One day.

public static final Duration
ONE_HOUR

One hour.

public static final Duration
ONE_MINUTE

One minute.

public static final long
serialVersionUID

The serialVersionUID required for java.io.Serializable.

public static final Duration
TEN_MINUTES

Ten minutes.

public static final Duration
THIRTY_MINUTES

Thirty minutes.

private final TimeUnit
timeUnit

The unit of time to specify time in. The minimum time unit is milliseconds.

public static final Duration
TWENTY_MINUTES

Twenty minutes.

public static final Duration
ZERO

Zero (no time).

Constructor Summary

AccessConstructor and Description
public
Duration()

Constructs an eternal duration (isEternal is true).

public
Duration(TimeUnit
the unit of time to specify time in. The minimum time unit is milliseconds.
timeUnit
,
long
how long, in the specified units, the cache entries should live.
durationAmount
)

Constructs a duration.

public
Duration(long
the start time (since the Epoc)
startTime
,
long
the end time (since the Epoc)
endTime
)

Constructs a Duration based on the duration between two specified points in time (since the Epoc), measured in milliseconds.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public long

Returns:

the adjusted time
getAdjustedTime
(long
the time from which to adjust given the duration
time
)

Calculates the adjusted time (represented in milliseconds from the Epoc) given a specified time in milliseconds (to be adjusted) by the duration.

public long

Returns:

the number of TimeUnits
getDurationAmount
()

Obtain the number of TimeUnits in the Duration

public TimeUnit

Returns:

the TimeUnit
getTimeUnit
()

Obtain the TimeUnit for the Duration

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true if the Duration is eternal
isEternal
()

Determines if a Duration is eternal (forever).

public boolean

Returns:

true if the Duration is zero
isZero
()

Determines if a Duration is zero.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

durationAmountback to summary
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.

ETERNALback to summary
public static final Duration ETERNAL

ETERNAL (forever).

FIVE_MINUTESback to summary
public static final Duration FIVE_MINUTES

Five minutes.

ONE_DAYback to summary
public static final Duration ONE_DAY

One day.

ONE_HOURback to summary
public static final Duration ONE_HOUR

One hour.

ONE_MINUTEback to summary
public static final Duration ONE_MINUTE

One minute.

serialVersionUIDback to summary
public static final long serialVersionUID

The serialVersionUID required for java.io.Serializable.

TEN_MINUTESback to summary
public static final Duration TEN_MINUTES

Ten minutes.

THIRTY_MINUTESback to summary
public static final Duration THIRTY_MINUTES

Thirty minutes.

timeUnitback to summary
private final TimeUnit timeUnit

The unit of time to specify time in. The minimum time unit is milliseconds.

TWENTY_MINUTESback to summary
public static final Duration TWENTY_MINUTES

Twenty minutes.

ZEROback to summary
public static final Duration ZERO

Zero (no time).

Constructor Detail

Durationback to summary
public Duration()

Constructs an eternal duration (isEternal is true). Since the duration is immutable the constant ETERNAL should be used alternatively.

Durationback to summary
public Duration(TimeUnit timeUnit, long durationAmount)

Constructs a duration. The eternal duration (isEternal is true) is represented by specifying null for timeUnit and 0 for durationAmount.

Parameters
timeUnit:TimeUnit

the unit of time to specify time in. The minimum time unit is milliseconds.

durationAmount:long

how long, in the specified units, the cache entries should live.

Exceptions
NullPointerException:
if timeUnit is null and the durationAmount is not 0
IllegalArgumentException:
if durationAmount is less than 0 or a TimeUnit less than milliseconds is specified
Durationback to summary
public Duration(long startTime, long endTime)

Constructs a 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.

Parameters
startTime:long

the start time (since the Epoc)

endTime:long

the end time (since the Epoc)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAdjustedTimeback to summary
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 value Long.MAX_VALUE is returned.

Parameters
time:long

the time from which to adjust given the duration

Returns:long

the adjusted time

getDurationAmountback to summary
public long getDurationAmount()

Obtain the number of TimeUnits in the Duration

Returns:long

the number of TimeUnits

getTimeUnitback to summary
public TimeUnit getTimeUnit()

Obtain the TimeUnit for the Duration

Returns:TimeUnit

the TimeUnit

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isEternalback to summary
public boolean isEternal()

Determines if a Duration is eternal (forever).

Returns:boolean

true if the Duration is eternal

isZeroback to summary
public boolean isZero()

Determines if a Duration is zero.

Returns:boolean

true if the Duration is zero