|
||||||||||
| 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>
com.twelvemonkeys.util.LRUHashMap<K,V>
public class LRUHashMap<K,V>
Map implementation with size limit, that keeps its entries in LRU (least recently used) order, also known as access-order. When the size limit is reached, the least recently accessed mappings are removed. The number of mappings to be removed from the map, is controlled by the trim factor.
setMaxSize(int)/getMaxSize().0.01f).
See setTrimFactor(float)/getTrimFactor().
| 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> |
| Constructor Summary | |
|---|---|
LRUHashMap()
Creates an LRUHashMap with default max size (1000 entries). |
|
LRUHashMap(int pMaxSize)
Creates an LRUHashMap with the given max size. |
|
LRUHashMap(Map<? extends K,? extends V> pContents)
Creates an LRUHashMap with initial mappings from the given map, and default max size (1000 entries). |
|
LRUHashMap(Map<? extends K,? extends V> pContents,
int pMaxSize)
Creates an LRUHashMap with initial mappings from the given map, and the given max size. |
|
| Method Summary | |
|---|---|
int |
getMaxSize()
Returns the maximum number of mappings in this map. |
float |
getTrimFactor()
Returns the current trim factor. |
void |
processRemoved(Map.Entry<K,V> pRemoved)
Default implementation does nothing. |
protected boolean |
removeEldestEntry(Map.Entry<K,V> pEldest)
always returns false, and instead invokes removeLRU()
if size >= maxSize. |
void |
removeLRU()
Removes the least recently used mapping(s) from this map. |
void |
setMaxSize(int pMaxSize)
Sets the maximum number of elements in this map. |
void |
setTrimFactor(float pTrimFactor)
Sets the trim factor. |
| Methods inherited from class java.util.LinkedHashMap |
|---|
clear, containsValue, get |
| Methods inherited from class java.util.HashMap |
|---|
clone, containsKey, entrySet, isEmpty, keySet, put, 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 |
|---|
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Constructor Detail |
|---|
public LRUHashMap()
Map interface.
LRUHashMap(int)public LRUHashMap(int pMaxSize)
pMaxSize - size limitpublic LRUHashMap(Map<? extends K,? extends V> pContents)
Map interface.
pContents - the map whose mappings are to be placed in this map.
May be null.LRUHashMap(java.util.Map, int)
public LRUHashMap(Map<? extends K,? extends V> pContents,
int pMaxSize)
pContents - the map whose mappings are to be placed in this map.
May be null.pMaxSize - size limit| Method Detail |
|---|
public int getMaxSize()
public void setMaxSize(int pMaxSize)
pMaxSize - new size limitremoveLRU()public float getTrimFactor()
The trim factor controls how many percent of the maps current size is
reclaimed, when performing an removeLRU operation.
Defaults to 1% (0.01f).
public void setTrimFactor(float pTrimFactor)
The trim factor controls how many percent of the maps current size is
reclaimed, when performing an removeLRU operation.
Defaults to 1% (0.01f).
pTrimFactor - the new trim factor. Acceptable values are between
0 (inclusive) and 1 (exclusive).removeLRU()protected boolean removeEldestEntry(Map.Entry<K,V> pEldest)
false, and instead invokes removeLRU()
if size >= maxSize.
removeEldestEntry in class LinkedHashMap<K,V>public void processRemoved(Map.Entry<K,V> pRemoved)
processRemoved in interface ExpiringMap<K,V>pRemoved - the removed mappingpublic void removeLRU()
How many mappings are removed from the map, is controlled by the trim factor. In any case, at least one mapping will be removed.
getTrimFactor()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||