Class PassiveExpiringMap<K,V> 
- Type Parameters:
- K- the type of the keys in this map
- V- the type of the values in this map
- All Implemented Interfaces:
- Serializable,- Map<K,,- V> - Get<K,,- V> - IterableGet<K,,- V> - IterableMap<K,,- V> - Put<K,- V> 
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
 PassiveExpiringMap.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
 containsValue(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 Collections.synchronizedMap(Map).
 This class may throw exceptions when accessed by concurrent threads without
 synchronization.
 
- Since:
- 4.0
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classAExpirationPolicythat returns an expiration time that is a constant about of time in the future from the current time.static interfaceA policy to determine the expiration time for key-value entries.
- 
Constructor SummaryConstructorsConstructorDescriptionDefault constructor.PassiveExpiringMap(long timeToLiveMillis) Constructs a map decorator that decorates the given map using the given time-to-live value measured in milliseconds to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.PassiveExpiringMap(long timeToLive, TimeUnit timeUnit) Constructs a map decorator using the given time-to-live value measured in the given time units of measure to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.PassiveExpiringMap(long timeToLive, TimeUnit timeUnit, Map<K, V> map) Constructs a map decorator that decorates the given map using the given time-to-live value measured in the given time units of measure to createPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.PassiveExpiringMap(long timeToLiveMillis, Map<K, V> map) Constructs a map decorator using the given time-to-live value measured in milliseconds to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.PassiveExpiringMap(Map<K, V> map) Constructs a map decorator that decorates the given map and results in entries NEVER expiring.PassiveExpiringMap(PassiveExpiringMap.ExpirationPolicy<K, V> expiringPolicy) Constructs a map decorator using the given expiration policy to determine expiration times.PassiveExpiringMap(PassiveExpiringMap.ExpirationPolicy<K, V> expiringPolicy, Map<K, V> map) Constructs a map decorator that decorates the given map and uses the given expiration policy to determine expiration times.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()NormalMap.clear()behavior with the addition of clearing all expiration entries as well.booleancontainsKey(Object key) All expired entries are removed from the map prior to determining the contains result.booleancontainsValue(Object value) All expired entries are removed from the map prior to determining the contains result.entrySet()All expired entries are removed from the map prior to returning the entry set.All expired entries are removed from the map prior to returning the entry value.booleanisEmpty()All expired entries are removed from the map prior to determining if it is empty.keySet()All expired entries are removed from the map prior to returning the key set.Associates the specified value with the specified key in this map.voidCopies all of the mappings from the specified map to this map.NormalMap.remove(Object)behavior with the addition of removing any expiration entry as well.intsize()All expired entries are removed from the map prior to returning the size.values()All expired entries are removed from the map prior to returning the value collection.Methods inherited from class org.apache.commons.collections4.map.AbstractMapDecoratordecorated, equals, hashCode, toStringMethods inherited from class org.apache.commons.collections4.map.AbstractIterableMapmapIteratorMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Constructor Details- 
PassiveExpiringMappublic PassiveExpiringMap()Default constructor. Constructs a map decorator that results in entries NEVER expiring.
- 
PassiveExpiringMapConstructs a map decorator using the given expiration policy to determine expiration times.- Parameters:
- expiringPolicy- the policy used to determine expiration times of entries as they are added.
- Throws:
- NullPointerException- if expiringPolicy is null
 
- 
PassiveExpiringMapConstructs 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- the policy used to determine expiration times of entries as they are added.
- map- the map to decorate, must not be null.
- Throws:
- NullPointerException- if the map or expiringPolicy is null.
 
- 
PassiveExpiringMapConstructs a map decorator that decorates the given map using the given time-to-live value measured in milliseconds to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.- Parameters:
- timeToLiveMillis- 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.
 
- 
PassiveExpiringMapConstructs a map decorator using the given time-to-live value measured in milliseconds to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy. If there are any elements already in the map being decorated, they will NEVER expire unless they are replaced.- Parameters:
- timeToLiveMillis- 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- the map to decorate, must not be null.
- Throws:
- NullPointerException- if the map is null.
 
- 
PassiveExpiringMapConstructs a map decorator using the given time-to-live value measured in the given time units of measure to create and use aPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration policy.- Parameters:
- timeToLive- 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- the unit of time for the- timeToLiveparameter, must not be null.
- Throws:
- NullPointerException- if the time unit is null.
 
- 
PassiveExpiringMapConstructs a map decorator that decorates the given map using the given time-to-live value measured in the given time units of measure to createPassiveExpiringMap.ConstantTimeToLiveExpirationPolicyexpiration 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- 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- the unit of time for the- timeToLiveparameter, must not be null.
- map- the map to decorate, must not be null.
- Throws:
- NullPointerException- if the map or time unit is null.
 
- 
PassiveExpiringMapConstructs 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- the map to decorate, must not be null.
- Throws:
- NullPointerException- if the map is null.
 
 
- 
- 
Method Details- 
clear
- 
containsKeyAll expired entries are removed from the map prior to determining the contains result. Tests for presence of a given key.- Specified by:
- containsKeyin interface- Get<K,- V> 
- Specified by:
- containsKeyin interface- Map<K,- V> 
- Overrides:
- containsKeyin class- AbstractMapDecorator<K,- V> 
- Parameters:
- key- key whose presence in this map is to be tested
- Returns:
- trueif this map contains a mapping for the specified key
- See Also:
 
- 
containsValueAll expired entries are removed from the map prior to determining the contains result. Tests for presence of a given value.- Specified by:
- containsValuein interface- Get<K,- V> 
- Specified by:
- containsValuein interface- Map<K,- V> 
- Overrides:
- containsValuein class- AbstractMapDecorator<K,- V> 
- Parameters:
- value- value whose presence in this map is to be tested
- Returns:
- trueif this map maps one or more keys to the specified value
- See Also:
 
- 
entrySetAll expired entries are removed from the map prior to returning the entry set. Gets a set view of the mappings contained in this map.
- 
getAll expired entries are removed from the map prior to returning the entry value. Gets a value at a given key.- Specified by:
- getin interface- Get<K,- V> 
- Specified by:
- getin interface- Map<K,- V> 
- Overrides:
- getin class- AbstractMapDecorator<K,- V> 
- Parameters:
- key- the key whose associated value is to be returned
- Returns:
- the value to which the specified key is mapped, or nullif this map contains no mapping for the key
- See Also:
 
- 
isEmptyAll expired entries are removed from the map prior to determining if it is empty. Tests whether this instance contains any key-value mappings.
- 
keySetAll expired entries are removed from the map prior to returning the key set. Gets a view of the keys contained in this map.
- 
putAssociates the specified value with the specified key in this map.Note that the return type is Object, rather than V as in the Map interface. See the class Javadoc for further info. 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.- Specified by:
- putin interface- Map<K,- V> 
- Specified by:
- putin interface- Put<K,- V> 
- Overrides:
- putin class- AbstractMapDecorator<K,- V> 
- Parameters:
- key- key with which the specified value is to be associated
- value- value to be associated with the specified key
- Returns:
- the previous value associated with key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey, if the implementation supportsnullvalues.)
- See Also:
 
- 
putAllDescription copied from interface:PutCopies all of the mappings from the specified map to this map.
- 
removeNormalMap.remove(Object)behavior with the addition of removing any expiration entry as well. Remove a key-value mappings.- Specified by:
- removein interface- Get<K,- V> 
- Specified by:
- removein interface- Map<K,- V> 
- Overrides:
- removein class- AbstractMapDecorator<K,- V> 
- Parameters:
- key- key whose mapping is to be removed from the map
- Returns:
- the previous value associated with key, ornullif there was no mapping forkey.
- See Also:
 
- 
sizeAll expired entries are removed from the map prior to returning the size. Gets the number of key-value mappings in this map.
- 
valuesAll expired entries are removed from the map prior to returning the value collection. Gets a a collection view of the values contained in this map.
 
-