|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
com.twelvemonkeys.util.TimeoutMap<K,V>
public class TimeoutMap<K,V>
A Map implementation that removes (exipres) its elements after
a given period. The map is by default backed by a HashMap,
or can be instantiated with any given Map as backing.
size() method of the map, or any of
its collection views, may not represent
the exact number of entries in the map at any given time.Iterator.hasNext()
and Iterator.next() or Iterator.remove(),
when iterating the collection views).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
protected Map<K,Map.Entry<K,V>> |
entries
|
protected long |
expiryTime
Expiry time |
protected int |
modCount
|
| Constructor Summary | |
|---|---|
TimeoutMap()
Creates a TimeoutMap with the default expiry time of 1 minute. |
|
TimeoutMap(long pExpiryTime)
Creates a TimeoutMap with the given expiry time (milliseconds). |
|
TimeoutMap(Map<? extends K,? extends V> pContents)
Creates a TimeoutMap containing the same elements as the given map
with the default expiry time of 1 minute. |
|
TimeoutMap(Map<K,Map.Entry<K,V>> pBacking,
Map<? extends K,? extends V> pContents,
long pExpiryTime)
Creates a TimeoutMap with the given expiry time (milliseconds). |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from this map. |
protected Object |
clone()
Returns a shallow copy of this AbstractMap instance: the keys
and values themselves are not cloned. |
boolean |
containsKey(Object pKey)
Returns true if this map contains a mapping for the specified
pKey. |
boolean |
containsValue(Object pValue)
Returns true if this map maps one or more keys to the
specified pValue. |
Set<Map.Entry<K,V>> |
entrySet()
|
V |
get(Object pKey)
Returns the value to which this map maps the specified pKey. |
long |
getExpiryTime()
Gets the maximum time any value will be kept in the map, before it expires. |
protected void |
init()
Default implementation, does nothing. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
Set<K> |
keySet()
|
protected Iterator<Map.Entry<K,V>> |
newEntryIterator()
|
protected Iterator<K> |
newKeyIterator()
|
protected Iterator<V> |
newValueIterator()
|
void |
processRemoved(Map.Entry pRemoved)
May be used by clients as a call-back to notify when mappings expire from the map. |
V |
put(K pKey,
V pValue)
Associates the specified pValue with the specified pKey in this map (optional operation). |
V |
remove(Object pKey)
Removes the mapping for this pKey from this map if present (optional operation). |
protected Map.Entry<K,V> |
removeEntry(Map.Entry<K,V> pEntry)
Removes the given entry from the Map. |
protected void |
removeExpiredEntries()
Removes any expired mappings. |
void |
setExpiryTime(long pExpiryTime)
Sets the maximum time any value will be kept in the map, before it expires. |
int |
size()
Returns the number of key-value mappings in this map. |
Collection<V> |
values()
|
| Methods inherited from class java.util.AbstractMap |
|---|
equals, hashCode, putAll, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
containsValue, equals, hashCode, putAll |
| Field Detail |
|---|
protected long expiryTime
protected Map<K,Map.Entry<K,V>> entries
protected transient volatile int modCount
| Constructor Detail |
|---|
public TimeoutMap()
TimeoutMap with the default expiry time of 1 minute.
This TimeoutMap will be backed by a new HashMap instance.
This is constructor is here to comply with the reccomendations for
"standard" constructors in the Map interface.
TimeoutMap(long)public TimeoutMap(Map<? extends K,? extends V> pContents)
TimeoutMap containing the same elements as the given map
with the default expiry time of 1 minute.
This TimeoutMap will be backed by a new HashMap instance,
and not the map passed in as a paramter.
This is constructor is here to comply with the reccomendations for
"standard" constructors in the Map interface.
pContents - the map whose mappings are to be placed in this map.
May be null.TimeoutMap(java.util.Map, Map, long),
Mappublic TimeoutMap(long pExpiryTime)
TimeoutMap with the given expiry time (milliseconds).
This TimeoutMap will be backed by a new HashMap instance.
pExpiryTime - the expiry time (time to live) for elements in this map
public TimeoutMap(Map<K,Map.Entry<K,V>> pBacking,
Map<? extends K,? extends V> pContents,
long pExpiryTime)
TimeoutMap with the given expiry time (milliseconds).
This TimeoutMap will be backed by the given Map.
Note that structurally modifying the backing map directly (not
through this map or its collection views), is not allowed, and will
produce undeterministic exceptions.
pBacking - the map that will be used as backing.pContents - the map whose mappings are to be placed in this map.
May be null.pExpiryTime - the expiry time (time to live) for elements in this map| Method Detail |
|---|
public long getExpiryTime()
public void setExpiryTime(long pExpiryTime)
pExpiryTime - the expiry time (time to live) for elements in this mappublic int size()
Integer.MAX_VALUE elements, returns
Integer.MAX_VALUE.
size in interface Map<K,V>public boolean isEmpty()
true if this map contains no key-value mappings.
isEmpty in interface Map<K,V>true if this map contains no key-value mappings.public boolean containsKey(Object pKey)
true if this map contains a mapping for the specified
pKey.
containsKey in interface Map<K,V>pKey - pKey whose presence in this map is to be tested.
true if this map contains a mapping for the specified
pKey.public V get(Object pKey)
null if the map contains no mapping for this pKey. A return
value of null does not necessarily indicate that the
map contains no mapping for the pKey; it's also possible that the map
explicitly maps the pKey to null. The containsKey
operation may be used to distinguish these two cases.
get in interface Map<K,V>pKey - pKey whose associated value is to be returned.
null if the map contains no mapping for this pKey.containsKey(java.lang.Object)
public V put(K pKey,
V pValue)
put in interface Map<K,V>pKey - pKey with which the specified pValue is to be associated.pValue - pValue to be associated with the specified pKey.
null
if there was no mapping for pKey. A null return can
also indicate that the map previously associated null
with the specified pKey, if the implementation supports
null values.public V remove(Object pKey)
remove in interface Map<K,V>pKey - pKey whose mapping is to be removed from the map.
null
if there was no mapping for pKey. A null return can
also indicate that the map previously associated null
with the specified pKey, if the implementation supports
null values.public void clear()
clear in interface Map<K,V>protected void removeExpiredEntries()
public Collection<V> values()
values in interface Map<K,V>public Set<Map.Entry<K,V>> entrySet()
entrySet in interface Map<K,V>public Set<K> keySet()
keySet in interface Map<K,V>protected Iterator<K> newKeyIterator()
protected Iterator<V> newValueIterator()
protected Iterator<Map.Entry<K,V>> newEntryIterator()
public void processRemoved(Map.Entry pRemoved)
ExpiringMap
processRemoved in interface ExpiringMap<K,V>pRemoved - the removed mappingprotected void init()
public boolean containsValue(Object pValue)
true if this map maps one or more keys to the
specified pValue. More formally, returns true if and only if
this map contains at least one mapping to a pValue v such that
(pValue==null ? v==null : pValue.equals(v)).
This implementation requires time linear in the map size for this
operation.
containsValue in interface Map<K,V>containsValue in class AbstractMap<K,V>pValue - pValue whose presence in this map is to be tested.
true if this map maps one or more keys to the
specified pValue.
protected Object clone()
throws CloneNotSupportedException
AbstractMap instance: the keys
and values themselves are not cloned.
clone in class AbstractMap<K,V>CloneNotSupportedExceptionprotected Map.Entry<K,V> removeEntry(Map.Entry<K,V> pEntry)
pEntry - the entry to be removed
null if nothing was removed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||