K
- the type of the keys in the mapV
- the type of the values in the mappublic class PassiveExpiringMap<K,V> extends AbstractMapDecorator<K,V> implements java.io.Serializable
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
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 Collections.synchronizedMap(Map)
.
This class may throw exceptions when accessed by concurrent threads without
synchronization.
Modifier and Type | Class and Description |
---|---|
static class |
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<K,V>
A
ExpirationPolicy
that returns a expiration time that is a
constant about of time in the future from the current time. |
static interface |
PassiveExpiringMap.ExpirationPolicy<K,V>
A policy to determine the expiration time for key-value entries.
|
Constructor and Description |
---|
PassiveExpiringMap()
Default constructor.
|
PassiveExpiringMap(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
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy expiration policy. |
PassiveExpiringMap(long timeToLiveMillis,
java.util.Map<K,V> map)
Construct a map decorator using the given time-to-live value measured in
milliseconds to create and use a
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy expiration policy. |
PassiveExpiringMap(long timeToLive,
java.util.concurrent.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
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy expiration policy. |
PassiveExpiringMap(long timeToLive,
java.util.concurrent.TimeUnit timeUnit,
java.util.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
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy expiration policy. |
PassiveExpiringMap(java.util.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)
Construct a map decorator using the given expiration policy to determine
expiration times.
|
PassiveExpiringMap(PassiveExpiringMap.ExpirationPolicy<K,V> expiringPolicy,
java.util.Map<K,V> map)
Construct a map decorator that decorates the given map and uses the given
expiration policy to determine expiration times.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Normal
Map.clear() behavior with the addition of clearing all
expiration entries as well. |
boolean |
containsKey(java.lang.Object key)
All expired entries are removed from the map prior to determining the
contains result.
|
boolean |
containsValue(java.lang.Object value)
All expired entries are removed from the map prior to determining the
contains result.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
All expired entries are removed from the map prior to returning the entry set.
|
V |
get(java.lang.Object key)
All expired entries are removed from the map prior to returning the entry value.
|
boolean |
isEmpty()
All expired entries are removed from the map prior to determining if it is empty.
|
java.util.Set<K> |
keySet()
All expired entries are removed from the map prior to returning the key set.
|
V |
put(K key,
V value)
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 . |
void |
putAll(java.util.Map<? extends K,? extends V> mapToCopy) |
V |
remove(java.lang.Object key)
Normal
Map.remove(Object) behavior with the addition of removing
any expiration entry as well. |
int |
size()
All expired entries are removed from the map prior to returning the size.
|
java.util.Collection<V> |
values()
All expired entries are removed from the map prior to returning the value collection.
|
equals, hashCode, toString
mapIterator
public PassiveExpiringMap()
public PassiveExpiringMap(PassiveExpiringMap.ExpirationPolicy<K,V> expiringPolicy)
expiringPolicy
- the policy used to determine expiration times of
entries as they are added.java.lang.NullPointerException
- if expiringPolicy is nullpublic PassiveExpiringMap(PassiveExpiringMap.ExpirationPolicy<K,V> expiringPolicy, java.util.Map<K,V> map)
expiringPolicy
- the policy used to determine expiration times of
entries as they are added.map
- the map to decorate, must not be null.java.lang.NullPointerException
- if the map or expiringPolicy is null.public PassiveExpiringMap(long timeToLiveMillis)
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy
expiration policy.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.public PassiveExpiringMap(long timeToLiveMillis, java.util.Map<K,V> map)
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy
expiration policy. If there
are any elements already in the map being decorated, they will NEVER
expire unless they are replaced.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.java.lang.NullPointerException
- if the map is null.public PassiveExpiringMap(long timeToLive, java.util.concurrent.TimeUnit timeUnit)
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy
expiration policy.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 timeToLive
parameter, must not be null.java.lang.NullPointerException
- if the time unit is null.public PassiveExpiringMap(long timeToLive, java.util.concurrent.TimeUnit timeUnit, java.util.Map<K,V> map)
PassiveExpiringMap.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.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 timeToLive
parameter, must not be null.map
- the map to decorate, must not be null.java.lang.NullPointerException
- if the map or time unit is null.public PassiveExpiringMap(java.util.Map<K,V> map)
map
- the map to decorate, must not be null.java.lang.NullPointerException
- if the map is null.public void clear()
Map.clear()
behavior with the addition of clearing all
expiration entries as well.public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
containsKey
in interface Get<K,V>
containsKey
in class AbstractMapDecorator<K,V>
Map.containsKey(Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
containsValue
in interface Get<K,V>
containsValue
in class AbstractMapDecorator<K,V>
Map.containsValue(Object)
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
public V get(java.lang.Object key)
public boolean isEmpty()
public java.util.Set<K> keySet()
public V put(K key, V value)
expiringPolicy
.
Note that the return type is Object, rather than V as in the Map interface. See the class Javadoc for further info.
public V remove(java.lang.Object key)
Map.remove(Object)
behavior with the addition of removing
any expiration entry as well.
public int size()
public java.util.Collection<V> values()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"