Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.map

public Class PassiveExpiringMap<K, V>

extends AbstractMapDecorator<K, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Collection, .HashMap, .Iterator, .Map, .Set, java.util.concurrent.TimeUnit

Decorates a Map to evict expired entries once their expiration time has been reached.

When putting a key-value pair in the map this decorator uses a ExpirationPolicy to determine how long the entry should remain alive as defined by an expiration time value.

When accessing the mapped value for a key, its expiration time is checked, and if it is a negative value or if it is greater than the current time, the mapped value is returned. Otherwise, the key is removed from the decorated map, and null is returned.

When invoking methods that involve accessing the entire map contents (i.e containsKey(Object), entrySet(), etc.) this decorator removes all expired entries prior to actually completing the invocation.

Note that PassiveExpiringMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using java.util.Collections#synchronizedMap(Map). This class may throw exceptions when accessed by concurrent threads without synchronization.

Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<
the type of the keys in the map
K
,
the type of the values in the map
V
>

A ExpirationPolicy that returns a expiration time that is a constant about of time in the future from the current time.

public static interface
PassiveExpiringMap.ExpirationPolicy<
the key object type.
K
,
the value object type
V
>

A policy to determine the expiration time for key-value entries.

Field Summary

Modifier and TypeField and Description
private final Map<Object, Long>
expirationMap

map used to manage expiration times for the actual map entries.

private final PassiveExpiringMap.ExpirationPolicy<K, V>
expiringPolicy

the policy used to determine time-to-live values for map entries.

private static final long
serialVersionUID

Serialization version

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
map

Constructor Summary

AccessConstructor and Description
public
PassiveExpiringMap()

Default constructor.

public
PassiveExpiringMap(final PassiveExpiringMap.ExpirationPolicy<K, V>
the policy used to determine expiration times of entries as they are added.
expiringPolicy
)

Construct a map decorator using the given expiration policy to determine expiration times.

public
PassiveExpiringMap(final PassiveExpiringMap.ExpirationPolicy<K, V>
the policy used to determine expiration times of entries as they are added.
expiringPolicy
,
final Map<K, V>
the map to decorate, must not be null.
map
)

Construct a map decorator that decorates the given map and uses the given expiration policy to determine expiration times.

public
PassiveExpiringMap(final long
the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLiveMillis
)

Construct a map decorator that decorates the given map using the given time-to-live value measured in milliseconds to create and use a ConstantTimeToLiveExpirationPolicy expiration policy.

public
PassiveExpiringMap(final long
the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLiveMillis
,
final Map<K, V>
the map to decorate, must not be null.
map
)

Construct a map decorator using the given time-to-live value measured in milliseconds to create and use a ConstantTimeToLiveExpirationPolicy expiration policy.

public
PassiveExpiringMap(final long
the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLive
,
final TimeUnit
the unit of time for the timeToLive parameter, must not be null.
timeUnit
)

Construct a map decorator using the given time-to-live value measured in the given time units of measure to create and use a ConstantTimeToLiveExpirationPolicy expiration policy.

public
PassiveExpiringMap(final long
the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLive
,
final TimeUnit
the unit of time for the timeToLive parameter, must not be null.
timeUnit
,
final Map<K, V>
the map to decorate, must not be null.
map
)

Construct a map decorator that decorates the given map using the given time-to-live value measured in the given time units of measure to create ConstantTimeToLiveExpirationPolicy expiration policy.

public
PassiveExpiringMap(final Map<K, V>
the map to decorate, must not be null.
map
)

Constructs a map decorator that decorates the given map and results in entries NEVER expiring.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Normal Map#clear() behavior with the addition of clearing all expiration entries as well.
public boolean
containsKey(final Object
key whose presence in this map is to be tested
key
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.containsKey.

Implements java.util.Map.containsKey, org.apache.commons.collections4.Get.containsKey.

All expired entries are removed from the map prior to determining the contains result.
public boolean
containsValue(final Object
value whose presence in this map is to be tested
value
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.containsValue.

Implements java.util.Map.containsValue, org.apache.commons.collections4.Get.containsValue.

All expired entries are removed from the map prior to determining the contains result.
public Set<Map.Entry<K, V>>
entrySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.entrySet.

Implements java.util.Map.entrySet, org.apache.commons.collections4.Get.entrySet.

All expired entries are removed from the map prior to returning the entry set.
public V
get(final Object
the key whose associated value is to be returned
key
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.get.

Implements java.util.Map.get, org.apache.commons.collections4.Get.get.

All expired entries are removed from the map prior to returning the entry value.
public boolean
isEmpty()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.isEmpty.

Implements java.util.Map.isEmpty, org.apache.commons.collections4.Get.isEmpty.

All expired entries are removed from the map prior to determining if it is empty.
private boolean

Returns:

true if expirationTimeObject is ≥ 0 and expirationTimeObject < now. false otherwise.
isExpired
(final long
the time in milliseconds used to compare against the expiration time.
now
,
final Long
the expiration time value retrieved from expirationMap, can be null.
expirationTimeObject
)

Determines if the given expiration time is less than now.

public Set<K>
keySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.keySet.

Implements java.util.Map.keySet, org.apache.commons.collections4.Get.keySet.

All expired entries are removed from the map prior to returning the key set.
private long
now()

The current time in milliseconds.

public V
put(final K
key with which the specified value is to be associated
key
,
final V
value to be associated with the specified key
value
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.put.

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Add the given key-value pair to this map as well as recording the entry's expiration time based on the current time in milliseconds and this map's expiringPolicy.
public void
putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map
mapToCopy
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.putAll.

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

public V
remove(final Object
key whose mapping is to be removed from the map
key
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.remove.

Implements java.util.Map.remove, org.apache.commons.collections4.Get.remove.

Normal Map#remove(Object) behavior with the addition of removing any expiration entry as well.
private void
removeAllExpired(final long now)

Removes all entries in the map whose expiration time is less than now.

private void
removeIfExpired(final Object key, final long now)

Removes the entry with the given key if the entry's expiration time is less than now.

public int
size()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.size.

Implements java.util.Map.size, org.apache.commons.collections4.Get.size.

All expired entries are removed from the map prior to returning the size.
private static long
validateAndConvertToMillis(final long
the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLive
,
final TimeUnit
the unit of time for the timeToLive parameter, must not be null.
timeUnit
)

First validate the input parameters.

public Collection<V>
values()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.values.

Implements java.util.Map.values, org.apache.commons.collections4.Get.values.

All expired entries are removed from the map prior to returning the value collection.
private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
decoratedequalshashCodetoString

Field Detail

expirationMapback to summary
private final Map<Object, Long> expirationMap

map used to manage expiration times for the actual map entries.

expiringPolicyback to summary
private final PassiveExpiringMap.ExpirationPolicy<K, V> expiringPolicy

the policy used to determine time-to-live values for map entries.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

Constructor Detail

PassiveExpiringMapback to summary
public PassiveExpiringMap()

Default constructor. Constructs a map decorator that results in entries NEVER expiring.

PassiveExpiringMapback to summary
public PassiveExpiringMap(final PassiveExpiringMap.ExpirationPolicy<K, V> expiringPolicy)

Construct a map decorator using the given expiration policy to determine expiration times.

Parameters
expiringPolicy:PassiveExpiringMap.ExpirationPolicy<K, V>

the policy used to determine expiration times of entries as they are added.

Exceptions
NullPointerException:
if expiringPolicy is null
PassiveExpiringMapback to summary
public PassiveExpiringMap(final PassiveExpiringMap.ExpirationPolicy<K, V> expiringPolicy, final Map<K, V> map)

Construct a map decorator that decorates the given map and uses the given expiration policy to determine expiration times. If there are any elements already in the map being decorated, they will NEVER expire unless they are replaced.

Parameters
expiringPolicy:PassiveExpiringMap.ExpirationPolicy<K, V>

the policy used to determine expiration times of entries as they are added.

map:Map<K, V>

the map to decorate, must not be null.

Exceptions
NullPointerException:
if the map or expiringPolicy is null.
PassiveExpiringMapback to summary
public PassiveExpiringMap(final long timeToLiveMillis)

Construct a map decorator that decorates the given map using the given time-to-live value measured in milliseconds to create and use a ConstantTimeToLiveExpirationPolicy expiration policy.

Parameters
timeToLiveMillis:long

the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

PassiveExpiringMapback to summary
public PassiveExpiringMap(final long timeToLiveMillis, final Map<K, V> map)

Construct a map decorator using the given time-to-live value measured in milliseconds to create and use a ConstantTimeToLiveExpirationPolicy expiration policy. If there are any elements already in the map being decorated, they will NEVER expire unless they are replaced.

Parameters
timeToLiveMillis:long

the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

map:Map<K, V>

the map to decorate, must not be null.

Exceptions
NullPointerException:
if the map is null.
PassiveExpiringMapback to summary
public PassiveExpiringMap(final long timeToLive, final TimeUnit timeUnit)

Construct a map decorator using the given time-to-live value measured in the given time units of measure to create and use a ConstantTimeToLiveExpirationPolicy expiration policy.

Parameters
timeToLive:long

the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

timeUnit:TimeUnit

the unit of time for the timeToLive parameter, must not be null.

Exceptions
NullPointerException:
if the time unit is null.
PassiveExpiringMapback to summary
public PassiveExpiringMap(final long timeToLive, final TimeUnit timeUnit, final Map<K, V> map)

Construct a map decorator that decorates the given map using the given time-to-live value measured in the given time units of measure to create ConstantTimeToLiveExpirationPolicy expiration policy. This policy is used to determine expiration times. If there are any elements already in the map being decorated, they will NEVER expire unless they are replaced.

Parameters
timeToLive:long

the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

timeUnit:TimeUnit

the unit of time for the timeToLive parameter, must not be null.

map:Map<K, V>

the map to decorate, must not be null.

Exceptions
NullPointerException:
if the map or time unit is null.
PassiveExpiringMapback to summary
public PassiveExpiringMap(final Map<K, V> map)

Constructs a map decorator that decorates the given map and results in entries NEVER expiring. If there are any elements already in the map being decorated, they also will NEVER expire.

Parameters
map:Map<K, V>

the map to decorate, must not be null.

Exceptions
NullPointerException:
if the map is null.

Method Detail

clearback to summary
public void clear()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Normal Map#clear() behavior with the addition of clearing all expiration entries as well.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(final Object key)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.containsKey.

Implements java.util.Map.containsKey, org.apache.commons.collections4.Get.containsKey.

Doc from java.util.Map.containsKey.

All expired entries are removed from the map prior to determining the contains result. Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
key:Object

key whose presence in this map is to be tested

Returns:boolean

true if this map contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(final Object value)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.containsValue.

Implements java.util.Map.containsValue, org.apache.commons.collections4.Get.containsValue.

Doc from java.util.Map.containsValue.

All expired entries are removed from the map prior to determining the contains result. Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Parameters
value:Object

value whose presence in this map is to be tested

Returns:boolean

true if this map maps one or more keys to the specified value

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.entrySet.

Implements java.util.Map.entrySet, org.apache.commons.collections4.Get.entrySet.

Doc from java.util.Map.entrySet.

All expired entries are removed from the map prior to returning the entry set. Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public V get(final Object key)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.get.

Implements java.util.Map.get, org.apache.commons.collections4.Get.get.

Doc from java.util.Map.get.

All expired entries are removed from the map prior to returning the entry value. Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

the key whose associated value is to be returned

Returns:V

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.isEmpty.

Implements java.util.Map.isEmpty, org.apache.commons.collections4.Get.isEmpty.

Doc from java.util.Map.isEmpty.

All expired entries are removed from the map prior to determining if it is empty. Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

Annotations
@Override
isExpiredback to summary
private boolean isExpired(final long now, final Long expirationTimeObject)

Determines if the given expiration time is less than now.

Parameters
now:long

the time in milliseconds used to compare against the expiration time.

expirationTimeObject:Long

the expiration time value retrieved from expirationMap, can be null.

Returns:boolean

true if expirationTimeObject is ≥ 0 and expirationTimeObject < now. false otherwise.

keySetback to summary
public Set<K> keySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.keySet.

Implements java.util.Map.keySet, org.apache.commons.collections4.Get.keySet.

Doc from java.util.Map.keySet.

All expired entries are removed from the map prior to returning the key set. Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<K>

a set view of the keys contained in this map

Annotations
@Override
nowback to summary
private long now()

The current time in milliseconds.

putback to summary
public V put(final K key, final V value)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.put.

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Doc from java.util.Map.put.

Add the given key-value pair to this map as well as recording the entry's expiration time based on the current time in milliseconds and this map's expiringPolicy.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@Override
putAllback to summary
public void putAll(final Map<? extends K, ? extends V> mapToCopy)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.putAll.

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
mapToCopy:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the map in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
removeback to summary
public V remove(final Object key)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.remove.

Implements java.util.Map.remove, org.apache.commons.collections4.Get.remove.

Doc from java.util.Map.remove.

Normal Map#remove(Object) behavior with the addition of removing any expiration entry as well. Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

key whose mapping is to be removed from the map

Returns:V

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
removeAllExpiredback to summary
private void removeAllExpired(final long now)

Removes all entries in the map whose expiration time is less than now. The exceptions are entries with negative expiration times; those entries are never removed.

See Also
isExpired(long, Long)
removeIfExpiredback to summary
private void removeIfExpired(final Object key, final long now)

Removes the entry with the given key if the entry's expiration time is less than now. If the entry has a negative expiration time, the entry is never removed.

sizeback to summary
public int size()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.size.

Implements java.util.Map.size, org.apache.commons.collections4.Get.size.

Doc from java.util.Map.size.

All expired entries are removed from the map prior to returning the size. Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of key-value mappings in this map

Annotations
@Override
validateAndConvertToMillisback to summary
private static long validateAndConvertToMillis(final long timeToLive, final TimeUnit timeUnit)

First validate the input parameters. If the parameters are valid, convert the given time measured in the given units to the same time measured in milliseconds.

Parameters
timeToLive:long

the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

timeUnit:TimeUnit

the unit of time for the timeToLive parameter, must not be null.

Exceptions
NullPointerException:
if the time unit is null.
valuesback to summary
public Collection<V> values()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.values.

Implements java.util.Map.values, org.apache.commons.collections4.Get.values.

Doc from java.util.Map.values.

All expired entries are removed from the map prior to returning the value collection. Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<V>

a collection view of the values contained in this map

Annotations
@Override
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the map out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream
org.apache.commons.collections4.map back to summary

public Class PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<K, V>

extends Object
implements PassiveExpiringMap.ExpirationPolicy<K, V>
Class Inheritance
  • java.lang.Object
  • org.apache.commons.collections4.map.PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy
All Implemented Interfaces
org.apache.commons.collections4.map.PassiveExpiringMap.ExpirationPolicy, java.io.Serializable
Type Parameters
<K>
the type of the keys in the map
<V>
the type of the values in the map

A ExpirationPolicy that returns a expiration time that is a constant about of time in the future from the current time.
Since
4.0

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serialization version

private final long
timeToLiveMillis

the constant time-to-live value measured in milliseconds.

Constructor Summary

AccessConstructor and Description
public
ConstantTimeToLiveExpirationPolicy()

Default constructor.

public
ConstantTimeToLiveExpirationPolicy(final long
the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLiveMillis
)

Construct a policy with the given time-to-live constant measured in milliseconds.

public
ConstantTimeToLiveExpirationPolicy(final long
the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.
timeToLive
,
final TimeUnit
the unit of time for the timeToLive parameter, must not be null.
timeUnit
)

Construct a policy with the given time-to-live constant measured in the given time unit of measure.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

if timeToLiveMillis ≥ 0, an expiration time of timeToLiveMillis + System#currentTimeMillis() is returned. Otherwise, -1 is returned indicating the entry never expires.
expirationTime
(final K
the key for the entry (ignored).
key
,
final V
the value for the entry (ignored).
value
)

Implements org.apache.commons.collections4.map.PassiveExpiringMap.ExpirationPolicy.expirationTime.

Determine the expiration time for the given key-value entry.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

timeToLiveMillisback to summary
private final long timeToLiveMillis

the constant time-to-live value measured in milliseconds.

Constructor Detail

ConstantTimeToLiveExpirationPolicyback to summary
public ConstantTimeToLiveExpirationPolicy()

Default constructor. Constructs a policy using a negative time-to-live value that results in entries never expiring.

ConstantTimeToLiveExpirationPolicyback to summary
public ConstantTimeToLiveExpirationPolicy(final long timeToLiveMillis)

Construct a policy with the given time-to-live constant measured in milliseconds. A negative time-to-live value indicates entries never expire. A zero time-to-live value indicates entries expire (nearly) immediately.

Parameters
timeToLiveMillis:long

the constant amount of time (in milliseconds) an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

ConstantTimeToLiveExpirationPolicyback to summary
public ConstantTimeToLiveExpirationPolicy(final long timeToLive, final TimeUnit timeUnit)

Construct a policy with the given time-to-live constant measured in the given time unit of measure.

Parameters
timeToLive:long

the constant amount of time an entry is available before it expires. A negative value results in entries that NEVER expire. A zero value results in entries that ALWAYS expire.

timeUnit:TimeUnit

the unit of time for the timeToLive parameter, must not be null.

Exceptions
NullPointerException:
if the time unit is null.

Method Detail

expirationTimeback to summary
public long expirationTime(final K key, final V value)

Implements org.apache.commons.collections4.map.PassiveExpiringMap.ExpirationPolicy.expirationTime.

Determine the expiration time for the given key-value entry.

Parameters
key:K

the key for the entry (ignored).

value:V

the value for the entry (ignored).

Returns:long

if timeToLiveMillis ≥ 0, an expiration time of timeToLiveMillis + System#currentTimeMillis() is returned. Otherwise, -1 is returned indicating the entry never expires.

Annotations
@Override
org.apache.commons.collections4.map back to summary

public Interface PassiveExpiringMap.ExpirationPolicy<K, V>

extends Serializable
Known Direct Implementers
org.apache.commons.collections4.map.PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy
Annotations
@FunctionalInterface
Type Parameters
<K>
the key object type.
<V>
the value object type

A policy to determine the expiration time for key-value entries.
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the expiration time value measured in milliseconds. A negative return value indicates the entry never expires.
expirationTime
(K
the key for the entry.
key
,
V
the value for the entry.
value
)

Determine the expiration time for the given key-value entry.

Method Detail

expirationTimeback to summary
public long expirationTime(K key, V value)

Determine the expiration time for the given key-value entry.

Parameters
key:K

the key for the entry.

value:V

the value for the entry.

Returns:long

the expiration time value measured in milliseconds. A negative return value indicates the entry never expires.