ExpiringMap<K,V>, Serializable, Cloneable, Map<K,V>public class LRUMap<K,V> extends LinkedMap<K,V> implements ExpiringMap<K,V>
setMaxSize(int)/getMaxSize().0.01f).
See setTrimFactor(float)/getTrimFactor().AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>LinkedMap.LinkedEntry<K,V>| Modifier and Type | Field | Description |
|---|---|---|
protected Map<K,Map.Entry<K,V>> |
entries |
|
protected int |
modCount |
accessOrder| Constructor | Description |
|---|---|
LRUMap() |
Creates an LRUMap with default max size (1000 entries).
|
LRUMap(int pMaxSize) |
Creates an LRUMap with the given max size.
|
LRUMap(Map<? extends K,? extends V> pContents) |
Creates an LRUMap with initial mappings from the given map,
and default max size (1000 entries).
|
LRUMap(Map<? extends K,? extends V> pContents,
int pMaxSize) |
Creates an LRUMap with initial mappings from the given map,
and the given max size.
|
LRUMap(Map<K,Map.Entry<K,V>> pBacking,
Map<? extends K,? extends V> pContents,
int pMaxSize) |
Creates an LRUMap with initial mappings from the given map,
and the given max size.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
clear() |
|
boolean |
containsKey(Object pKey) |
|
Set<Map.Entry<K,V>> |
entrySet() |
|
int |
getMaxSize() |
Returns the maximum number of mappings in this map.
|
float |
getTrimFactor() |
Returns the current trim factor.
|
boolean |
isEmpty() |
|
Set<K> |
keySet() |
|
void |
processRemoved(Map.Entry<K,V> pRemoved) |
Default implementation does nothing.
|
protected boolean |
removeEldestEntry(Map.Entry pEldest) |
always returns
false, and instead invokes removeLRU()
if size >= maxSize. |
protected Map.Entry<K,V> |
removeEntry(Map.Entry<K,V> pEntry) |
Removes the given entry from the Map.
|
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.
|
int |
size() |
|
Collection<V> |
values() |
equals, hashCode, putAll, toStringclone, containsValue, get, init, newEntryIterator, newKeyIterator, newValueIterator, put, removeclear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuespublic LRUMap()
Map interface.LRUMap(int)public LRUMap(int pMaxSize)
pMaxSize - size limitpublic LRUMap(Map<? extends K,? extends V> pContents)
Map interface.pContents - the map whose mappings are to be placed in this map.
May be null.LRUMap(Map, int)public LRUMap(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 limitpublic LRUMap(Map<K,Map.Entry<K,V>> pBacking, Map<? extends K,? extends V> pContents, int pMaxSize)
pBacking - the backing map of this map. Must be either empty, or
the same map as pContents.pContents - the map whose mappings are to be placed in this map.
May be null.pMaxSize - max sizepublic 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 pEldest)
false, and instead invokes removeLRU()
if size >= maxSize.removeEldestEntry in class LinkedMap<K,V>pEldest - The least recently inserted entry in the map, or if
this is an access-ordered map, the least recently accessed
entry. This is the entry that will be removed it this
method returns true. If the map was empty prior
to the put or putAll invocation resulting
in this invocation, this will be the entry that was just
inserted; in other words, if the map contains a single
entry, the eldest entry is also the newest.true if the eldest entry should be removed
from the map; false if it should be retained.protected Map.Entry<K,V> removeEntry(Map.Entry<K,V> pEntry)
pEntry - the entry to be removednull if nothing was removed.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()public int size()
size in interface Map<K,V>size in class AbstractMap<K,V>public void clear()
clear in interface Map<K,V>clear in class AbstractMap<K,V>public boolean isEmpty()
isEmpty in interface Map<K,V>isEmpty in class AbstractMap<K,V>public boolean containsKey(Object pKey)
containsKey in interface Map<K,V>containsKey in class AbstractMap<K,V>public Collection<V> values()
values in interface Map<K,V>values in class AbstractMap<K,V>public Set<Map.Entry<K,V>> entrySet()
entrySet in interface Map<K,V>entrySet in class AbstractMap<K,V>public Set<K> keySet()
keySet in interface Map<K,V>keySet in class AbstractMap<K,V>Copyright © 2018. All rights reserved.