public class WeakHashLRUImpl<K> extends java.lang.Object implements WeakHashLRU<K>
Modifier and Type | Field and Description |
---|---|
private java.util.WeakHashMap<K,DoubleNode<K,java.lang.Object>> |
byKey |
private java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,java.lang.Object>> |
byKeyNotWeak |
private boolean |
isWeak |
private DoubleNode<K,java.lang.Object> |
lru |
private DoubleNode<K,java.lang.Object> |
mru |
private java.lang.ref.ReferenceQueue<? super K> |
myQueue |
private static java.lang.Object |
VALUE |
Constructor and Description |
---|
WeakHashLRUImpl(boolean isWeak) |
Modifier and Type | Method and Description |
---|---|
void |
add(K key)
Adds the given key to the LRU.
|
private DoubleNode<K,java.lang.Object> |
addToHead(K key) |
void |
clear()
Removes all entries from this LRU
|
private void |
clearStale() |
void |
clearStaleReferences()
Causes stale references to be cleared from the data
structures.
|
boolean |
contains(K key)
Tells if the given key is in the LRU
|
void |
releaseMatching(CacheKeyFilter<K> filter)
Releases all keys that match the filter
|
K |
remove()
Removes the key that was Least
Recently Used
|
private K |
remove(DoubleNode<K,java.lang.Object> removeMe) |
boolean |
remove(K key)
Removes the given key from the LRU, if found
|
private boolean |
removeNoClear(K key) |
int |
size()
Returns the number of elements currently
in the clock.
|
java.lang.String |
toString() |
private static final java.lang.Object VALUE
private final boolean isWeak
private final java.util.WeakHashMap<K,DoubleNode<K,java.lang.Object>> byKey
private final java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,java.lang.Object>> byKeyNotWeak
private final java.lang.ref.ReferenceQueue<? super K> myQueue
private DoubleNode<K,java.lang.Object> mru
private DoubleNode<K,java.lang.Object> lru
private DoubleNode<K,java.lang.Object> addToHead(K key)
private K remove(DoubleNode<K,java.lang.Object> removeMe)
public void add(K key)
WeakHashLRU
add
in interface WeakHashLRU<K>
key
- Must not be nullpublic boolean contains(K key)
WeakHashLRU
contains
in interface WeakHashLRU<K>
key
- The key to search for, may not be nullpublic boolean remove(K key)
WeakHashLRU
remove
in interface WeakHashLRU<K>
key
- The key to remove, may not be nullprivate boolean removeNoClear(K key)
public int size()
WeakHashLRU
size
in interface WeakHashLRU<K>
public K remove()
WeakHashLRU
remove
in interface WeakHashLRU<K>
public void releaseMatching(CacheKeyFilter<K> filter)
WeakHashLRU
releaseMatching
in interface WeakHashLRU<K>
filter
- A non-null filter that can be used
to delete every key that matches the filterpublic void clear()
WeakHashLRU
clear
in interface WeakHashLRU<K>
public void clearStaleReferences()
WeakHashLRU
clearStaleReferences
in interface WeakHashLRU<K>
private void clearStale()
public java.lang.String toString()
toString
in class java.lang.Object