public class LRUHashMap<K,V> extends LinkedHashMap<K,V> implements ExpiringMap<K,V>
setMaxSize(int)/getMaxSize().0.01f).
See setTrimFactor(float)/getTrimFactor().AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
clear, containsValue, getclone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, valuesequals, hashCode, toStringpublic 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 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()Copyright © 2017. All Rights Reserved.