Class LRUMap
- All Implemented Interfaces:
Serializable, Cloneable, Map, BoundedMap, IterableMap, OrderedMap, SizedMap
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLinkedMap
AbstractLinkedMap.EntrySetIterator<K,V>, AbstractLinkedMap.KeySetIterator<K>, AbstractLinkedMap.LinkEntry<K, V>, AbstractLinkedMap.LinkIterator<K, V>, AbstractLinkedMap.LinkMapIterator<K, V>, AbstractLinkedMap.ValuesIterator<V> Nested classes/interfaces inherited from class AbstractHashedMap
AbstractHashedMap.EntrySet<K,V>, AbstractHashedMap.HashEntry<K, V>, AbstractHashedMap.HashIterator<K, V>, AbstractHashedMap.HashMapIterator<K, V>, AbstractHashedMap.KeySet<K>, AbstractHashedMap.Values<V> Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields inherited from class LRUMap
DEFAULT_MAX_SIZEFields inherited from class AbstractHashedMap
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReads the data necessary forput()to work in the superclass.protected voidWrites the data necessary forput()to work in deserialization.intThe maximum number of entries, or Integer.MAX_VALUE for no limit.booleanisFull()Returns true if this map is full and no new mappings can be added.intmaxSize()Gets the maximum size of the map (the bound).voidoverflowRemoved(Object key, Object value) Overridable callback for when an overflow entry is automatically removed.protected booleanSubclass method to control removal of the least recently used entry from the map.voidsetMaxSize(int max) The maximum number of entries, or Integer.MAX_VALUE for no limit.Methods inherited from class LRUMap
addMapping, clone, get, get, isScanUntilRemovable, moveToMRU, reuseMapping, updateEntryMethods inherited from class AbstractLinkedMap
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, getEntry, init, lastKey, mapIterator, nextKey, previousKey, removeEntryMethods inherited from class AbstractHashedMap
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, valuesMethods inherited from interface IterableMap
clear, put, putAllMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
LRUMap
public LRUMap() -
LRUMap
public LRUMap(int initCapacity) -
LRUMap
public LRUMap(int initCapacity, float loadFactor) -
LRUMap
-
-
Method Details
-
getMaxSize
public int getMaxSize()Description copied from interface:SizedMapThe maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
getMaxSizein interfaceSizedMap
-
setMaxSize
public void setMaxSize(int max) Description copied from interface:SizedMapThe maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
setMaxSizein interfaceSizedMap
-
overflowRemoved
Description copied from interface:SizedMapOverridable callback for when an overflow entry is automatically removed.- Specified by:
overflowRemovedin interfaceSizedMap
-
maxSize
public int maxSize()Description copied from class:LRUMapGets the maximum size of the map (the bound).- Specified by:
maxSizein interfaceBoundedMap- Overrides:
maxSizein classLRUMap- Returns:
- the maximum number of elements the map can hold
-
isFull
-
removeLRU
Description copied from class:LRUMapSubclass method to control removal of the least recently used entry from the map.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.
-
doWriteObject
Description copied from class:LRUMapWrites the data necessary forput()to work in deserialization.- Overrides:
doWriteObjectin classLRUMap- Parameters:
out- the output stream- Throws:
IOException- if an error occurs while writing to the stream
-
doReadObject
Description copied from class:LRUMapReads the data necessary forput()to work in the superclass.- Overrides:
doReadObjectin classLRUMap- Parameters:
in- the input stream- Throws:
IOException- if an error occurs while reading from the streamClassNotFoundException- if an object read from the stream can not be loaded
-