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 SummaryConstructors
- 
Method SummaryModifier 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Constructor Details- 
AbstractLRUMappublic AbstractLRUMap()This creates an unbounded version. Setting the max objects will result in spooling on subsequent puts.
 
- 
- 
Method Details- 
sizeThis simply returns the number of elements in the map.
- 
clearThis removes all the items. It clears the map and the double linked list.
- 
isEmptyReturns true if the map is empty.
- 
containsKeyReturns true if the map contains an element for the supplied key.- Specified by:
- containsKeyin interface- Map<K,- V> 
- See Also:
 
- 
containsValueThis is an expensive operation that determines if the object supplied is mapped to any key.- Specified by:
- containsValuein interface- Map<K,- V> 
- See Also:
 
- 
values
- 
putAll
- 
get
- 
getQuietThis 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
- 
dumpCacheEntriesDump the cache entries from first to list for debugging.
- 
dumpMapDump the cache map for debugging.
- 
verifyCacheChecks to see if all the items that should be in the cache are. Checks consistency between List and map.
- 
processRemovedLRUThis 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
 
- 
entrySetThis 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
 
-