public abstract class AbstractLRUMap<K,V> extends Object implements Map<K,V>
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.
Constructor and Description |
---|
AbstractLRUMap()
This creates an unbounded version.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
This removes all the items.
|
boolean |
containsKey(Object key)
Returns true if the map contains an element for the supplied key.
|
boolean |
containsValue(Object value)
This is an expensive operation that determines if the object supplied is mapped to any key.
|
void |
dumpCacheEntries()
Dump the cache entries from first to list for debugging.
|
void |
dumpMap()
Dump the cache map for debugging.
|
Set<Map.Entry<K,V>> |
entrySet()
This returns a set of entries.
|
V |
get(Object key) |
V |
getQuiet(Object key)
This gets an element out of the map without adjusting it's position in the LRU.
|
IStats |
getStatistics() |
boolean |
isEmpty()
Returns true if the map is empty.
|
Set<K> |
keySet() |
protected void |
processRemovedLRU(K key,
V value)
This is called when an item is removed from the LRU.
|
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> source) |
V |
remove(Object key) |
protected abstract boolean |
shouldRemove() |
int |
size()
This simply returns the number of elements in the map.
|
Collection<V> |
values() |
protected void |
verifyCache()
Checks to see if all the items that should be in the cache are.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public AbstractLRUMap()
public int size()
size
in interface Map<K,V>
Map.size()
public void clear()
clear
in interface Map<K,V>
Map.clear()
public boolean isEmpty()
isEmpty
in interface Map<K,V>
Map.isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
Map.containsKey(Object)
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
Map.containsValue(Object)
public Collection<V> values()
public V getQuiet(Object key)
key
- protected abstract boolean shouldRemove()
public void dumpCacheEntries()
public void dumpMap()
protected void verifyCache()
protected void processRemovedLRU(K key, V value)
Children can implement this method for special behavior.
key
- value
- public IStats getStatistics()
public Set<Map.Entry<K,V>> entrySet()
TODO we should return out own set wrapper, so we can avoid the extra object creation if it isn't necessary.
entrySet
in interface Map<K,V>
Map.entrySet()
Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.