|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.limewire.collection.FixedsizeForgetfulHashMap<K,V>
public class FixedsizeForgetfulHashMap<K,V>
Provides a better-defined replacement policy version of
ForgetfulHashMap. Like ForgetfulHashMap, this is a
mapping that "forgets" keys and values using a FIFO replacement policy, much
like a cache.
Specifically, FixedsizeForgetfulHashMap allows a
key to be re-mapped to a different value and then "renews" this key so it
is the last key to be replaced (done in constant time).
FixedsizeForgetfulHashMap<String, String> ffhm =
new FixedsizeForgetfulHashMap<String, String>(3);
ffhm.put("myKey1", "Abby");
ffhm.put("myKey2", "Bob");
ffhm.put("myKey3", "Chris");
System.out.println(ffhm);
ffhm.put("myKey4", "Dan");
System.out.println(ffhm);
ffhm.put("myKey3", "replace");
System.out.println(ffhm);
Output:
{myKey1=Abby, myKey2=Bob, myKey3=Chris}
{myKey2=Bob, myKey3=Chris, myKey4=Dan}
{myKey2=Bob, myKey4=Dan, myKey3=replace}
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Constructor Summary | |
|---|---|
FixedsizeForgetfulHashMap(int size)
Create a new instance that holds only the last "size" entries. |
|
FixedsizeForgetfulHashMap(int size,
int initialCapacity)
Create a new instance that holds only the last "size" entries, using the given initialCapacity and a loadFactor of 0.75. |
|
FixedsizeForgetfulHashMap(int size,
int initialCapacity,
float loadFactor)
Create a new instance that holds only the last "size" entries, using the given initialCapacity & loadFactor. |
|
| Method Summary | |
|---|---|
FixedsizeForgetfulHashMap<K,V> |
clone()
Returns a shallow copy of this Map instance: the keys and values themselves are not cloned. |
boolean |
isFull()
Tests if the map is full |
V |
put(K key,
V value)
Overridden to ensure that remapping a key renews the value in the linked list. |
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest)
Returns true if the eldest entry should be removed. |
Map.Entry<K,V> |
removeLRUEntry()
Removes the least recently used entry from the map |
| Methods inherited from class java.util.LinkedHashMap |
|---|
clear, containsValue, get |
| Methods inherited from class java.util.HashMap |
|---|
containsKey, entrySet, isEmpty, keySet, putAll, 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 |
|---|
containsKey, entrySet, equals, hashCode, isEmpty, keySet, putAll, remove, size, values |
| Constructor Detail |
|---|
public FixedsizeForgetfulHashMap(int size)
size - the number of entries to hold
IllegalArgumentException - if size is less < 1.
public FixedsizeForgetfulHashMap(int size,
int initialCapacity)
size - the number of entries to hold
IllegalArgumentException - if size is less < 1.
public FixedsizeForgetfulHashMap(int size,
int initialCapacity,
float loadFactor)
size - the number of entries to hold
IllegalArgumentException - if size is less < 1.| Method Detail |
|---|
public boolean isFull()
public Map.Entry<K,V> removeLRUEntry()
public FixedsizeForgetfulHashMap<K,V> clone()
clone in class HashMap<K,V>protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
removeEldestEntry in class LinkedHashMap<K,V>
public V put(K key,
V value)
put in interface Map<K,V>put in class HashMap<K,V>
|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||