org.ehcache.expiry
Class Duration

java.lang.Object
  extended by org.ehcache.expiry.Duration

public final class Duration
extends java.lang.Object

A time duration in a given TimeUnit.


Field Summary
static Duration INFINITE
          The infinite Duration.
static Duration ZERO
          The zero Duration.
 
Constructor Summary
Duration(long length, java.util.concurrent.TimeUnit timeUnit)
          Instantiates a new Duration of the given length and TimeUnit.
 
Method Summary
 boolean equals(java.lang.Object obj)
          
 long getLength()
          Gets the length of time this Duration represents.
 java.util.concurrent.TimeUnit getTimeUnit()
          Gets the TimeUnit of this Duration.
 int hashCode()
          
 boolean isInfinite()
          Indicates if this duration represents INFINITE or an infinite Duration.
static Duration of(long length, java.util.concurrent.TimeUnit timeUnit)
          Convenience method to create a Duration with the specified values.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITE

public static final Duration INFINITE
The infinite Duration.

This constant should be used to express a lack of a concrete expiration time (ie. "eternal").


ZERO

public static final Duration ZERO
The zero Duration.

Constructor Detail

Duration

public Duration(long length,
                java.util.concurrent.TimeUnit timeUnit)
Instantiates a new Duration of the given length and TimeUnit.

Parameters:
length - the duration length
timeUnit - the time unit
Throws:
java.lang.NullPointerException - if the given time unit is null
java.lang.IllegalArgumentException - if the given length is less than zero
Method Detail

of

public static Duration of(long length,
                          java.util.concurrent.TimeUnit timeUnit)
Convenience method to create a Duration with the specified values.

Parameters:
length - the duration length
timeUnit - the time unit
Returns:
a new Duration
See Also:
Duration(long, TimeUnit)

getLength

public long getLength()
Gets the length of time this Duration represents.

Returns:
the length of this instance
Throws:
java.lang.IllegalStateException - if this instance is INFINITE
See Also:
getTimeUnit()

getTimeUnit

public java.util.concurrent.TimeUnit getTimeUnit()
Gets the TimeUnit of this Duration.

Returns:
the TimeUnit of this instance
Throws:
java.lang.IllegalStateException - if this instance is INFINITE
See Also:
getLength()

isInfinite

public boolean isInfinite()
Indicates if this duration represents INFINITE or an infinite Duration.

Returns:
true if this instance is the special Forever value

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object