com.limegroup.gnutella.util
Class ForgetfulHashMap
java.lang.Object
java.util.AbstractMap
java.util.HashMap
com.limegroup.gnutella.util.ForgetfulHashMap
- All Implemented Interfaces:
- java.lang.Cloneable, java.util.Map, java.io.Serializable
- public class ForgetfulHashMap
- extends java.util.HashMap
A mapping that "forgets" keys and values using a FIFO replacement
policy, much like a cache.
More formally, a ForgetfulHashMap is a sequence of key-value pairs
[ (K1, V1), ... (KN, VN) ] ordered from youngest to oldest. When
inserting a new pair, (KN, VN) is discarded if N is greater than
some threshold. This threshold is fixed when the table is
constructed. However, this property may not hold if keys are
remapped to different values; if you need this, use
FixedsizeForgetfulHashmap.
Technically, this not a valid subtype of HashMap, but it makes
implementation really easy. =) Also, ForgetfulHashMap is not
synchronized.
- See Also:
- Serialized Form
Constructor Summary |
ForgetfulHashMap(int size)
Create a new ForgetfulHashMap that holds only the last "size" entries. |
Method Summary |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
void |
putAll(java.util.Map t)
Calls put on all keys in t. |
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, remove, size, values |
Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
ForgetfulHashMap
public ForgetfulHashMap(int size)
- Create a new ForgetfulHashMap that holds only the last "size" entries.
- Parameters:
size
- the number of entries to hold
- Throws:
java.lang.IllegalArgumentException
- if size is less < 1.
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
putAll
public void putAll(java.util.Map t)
- Calls put on all keys in t. See put(Object, Object) for
specification.