public class LRUMap extends LRUMap implements SizedMap
LRUMap
that can change its
maximum size.AbstractLinkedMap.EntrySetIterator<K,V>, AbstractLinkedMap.KeySetIterator<K>, AbstractLinkedMap.LinkEntry<K,V>, AbstractLinkedMap.LinkIterator<K,V>, AbstractLinkedMap.LinkMapIterator<K,V>, AbstractLinkedMap.ValuesIterator<V>
AbstractHashedMap.EntrySet<K,V>, AbstractHashedMap.HashEntry<K,V>, AbstractHashedMap.HashIterator<K,V>, AbstractHashedMap.HashMapIterator<K,V>, AbstractHashedMap.KeySet<K>, AbstractHashedMap.Values<V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
DEFAULT_MAX_SIZE
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID
Constructor and Description |
---|
LRUMap() |
LRUMap(int initCapacity) |
LRUMap(int initCapacity,
float loadFactor) |
LRUMap(Map map) |
Modifier and Type | Method and Description |
---|---|
protected void |
doReadObject(ObjectInputStream in)
Reads the data necessary for
put() to work in the superclass. |
protected void |
doWriteObject(ObjectOutputStream out)
Writes the data necessary for
put() to work in deserialization. |
int |
getMaxSize()
The maximum number of entries, or Integer.MAX_VALUE for no limit.
|
boolean |
isFull()
Returns true if this map is full and no new mappings can be added.
|
int |
maxSize()
Gets the maximum size of the map (the bound).
|
void |
overflowRemoved(Object key,
Object value)
Overridable callback for when an overflow entry is automatically removed.
|
protected boolean |
removeLRU(AbstractLinkedMap.LinkEntry entry)
Subclass method to control removal of the least recently used entry from the map.
|
void |
setMaxSize(int max)
The maximum number of entries, or Integer.MAX_VALUE for no limit.
|
addMapping, clone, get, get, isScanUntilRemovable, moveToMRU, reuseMapping, updateEntry
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, getEntry, init, lastKey, mapIterator, nextKey, previousKey, removeEntry
calculateNewCapacity, calculateThreshold, checkCapacity, containsKey, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, remove, removeMapping, reuseEntry, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
clear, mapIterator, put, putAll
public LRUMap()
public LRUMap(int initCapacity)
public LRUMap(int initCapacity, float loadFactor)
public LRUMap(Map map)
public int getMaxSize()
SizedMap
getMaxSize
in interface SizedMap
public void setMaxSize(int max)
SizedMap
setMaxSize
in interface SizedMap
public void overflowRemoved(Object key, Object value)
SizedMap
overflowRemoved
in interface SizedMap
public int maxSize()
LRUMap
maxSize
in interface BoundedMap
maxSize
in class LRUMap
public boolean isFull()
LRUMap
protected boolean removeLRU(AbstractLinkedMap.LinkEntry entry)
LRUMap
This method exists for subclasses to override. A subclass may wish to provide cleanup of resources when an entry is removed. For example:
protected boolean removeLRU(LinkEntry entry) { releaseResources(entry.getValue()); // release resources held by entry return true; // actually delete entry }
Alternatively, a subclass may choose to not remove the entry or selectively keep certain LRU entries. For example:
protected boolean removeLRU(LinkEntry entry) { if (entry.getKey().toString().startsWith("System.")) { return false; // entry not removed from LRUMap } else { return true; // actually delete entry } }The effect of returning false is dependent on the scanUntilRemovable flag. If the flag is true, the next LRU entry will be passed to this method and so on until one returns false and is removed, or every entry in the map has been passed. If the scanUntilRemovable flag is false, the map will exceed the maximum size.
NOTE: Commons Collections 3.0 passed the wrong entry to this method. This is fixed in version 3.1 onwards.
protected void doWriteObject(ObjectOutputStream out) throws IOException
LRUMap
put()
to work in deserialization.doWriteObject
in class LRUMap
out
- the output streamIOException
- if an error occurs while writing to the streamprotected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException
LRUMap
put()
to work in the superclass.doReadObject
in class LRUMap
in
- the input streamIOException
- if an error occurs while reading from the streamClassNotFoundException
- if an object read from the stream can not be loadedCopyright © 2006–2022 Apache Software Foundation. All rights reserved.