Class AbstractLRUMap<K,V>
java.lang.Object
org.apache.commons.jcs3.utils.struct.AbstractLRUMap<K,V>
- All Implemented Interfaces:
Map<K,V>
- Direct Known Subclasses:
BlockDiskKeyStore.LRUMapSizeLimited,IndexedDiskCache.LRUMapSizeLimited,LRUMap
This is a simple LRUMap. It implements most of the map methods. It is not recommended that you
use any but put, get, remove, and clear.
Children can implement the processRemovedLRU method if they want to handle the removal of the least recently used item.
This class was abstracted out of the LRU Memory cache. Put, remove, and get should be thread safe. It uses a hashtable and our own double linked list.
Locking is done on the instance.
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()This removes all the items.booleancontainsKey(Object key) Returns true if the map contains an element for the supplied key.booleancontainsValue(Object value) This is an expensive operation that determines if the object supplied is mapped to any key.voidDump the cache entries from first to list for debugging.voiddumpMap()Dump the cache map for debugging.entrySet()This returns a set of entries.This gets an element out of the map without adjusting it's position in the LRU.booleanisEmpty()Returns true if the map is empty.keySet()protected voidprocessRemovedLRU(K key, V value) This is called when an item is removed from the LRU.voidprotected abstract booleanintsize()This simply returns the number of elements in the map.values()protected voidChecks to see if all the items that should be in the cache are.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
AbstractLRUMap
public AbstractLRUMap()This creates an unbounded version. Setting the max objects will result in spooling on subsequent puts.
-
-
Method Details
-
size
This simply returns the number of elements in the map. -
clear
This removes all the items. It clears the map and the double linked list. -
isEmpty
Returns true if the map is empty. -
containsKey
Returns true if the map contains an element for the supplied key.- Specified by:
containsKeyin interfaceMap<K,V> - See Also:
-
containsValue
This is an expensive operation that determines if the object supplied is mapped to any key.- Specified by:
containsValuein interfaceMap<K,V> - See Also:
-
values
-
putAll
-
get
-
getQuiet
This gets an element out of the map without adjusting it's position in the LRU. In other words, this does not count as being used. If the element is the last item in the list, it will still be the last time in the list.- Parameters:
key-- Returns:
- Object
-
remove
-
put
-
shouldRemove
-
dumpCacheEntries
Dump the cache entries from first to list for debugging. -
dumpMap
Dump the cache map for debugging. -
verifyCache
Checks to see if all the items that should be in the cache are. Checks consistency between List and map. -
processRemovedLRU
This is called when an item is removed from the LRU. We just log some information.Children can implement this method for special behavior.
- Parameters:
key-value-
-
getStatistics
- Returns:
- IStats
-
entrySet
This returns a set of entries. Our LRUMapEntry is used since the value stored in the underlying map is a node in the double linked list. We wouldn't want to return this to the client, so we construct a new entry with the payload of the node.TODO we should return out own set wrapper, so we can avoid the extra object creation if it isn't necessary.
-
keySet
-