public class WeakHashClockImpl<K,V> extends java.lang.Object implements WeakHashClock<K,V>
Modifier and Type | Field and Description |
---|---|
private java.util.WeakHashMap<K,DoubleNode<K,V>> |
byKey |
private java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,V>> |
byKeyNotWeak |
private DoubleNode<K,V> |
dot |
private DoubleNode<K,V> |
head |
private boolean |
isWeak |
private java.lang.ref.ReferenceQueue<? super K> |
myQueue |
private DoubleNode<K,V> |
tail |
Constructor and Description |
---|
WeakHashClockImpl(boolean isWeak) |
Modifier and Type | Method and Description |
---|---|
private DoubleNode<K,V> |
addBeforeDot(K key,
V value) |
void |
clear()
Sets the clock size back to zero, no entries
|
void |
clearStaleReferences()
Causes stale references to be cleared from the data
structures.
|
V |
get(K key)
Gets the given key, returning null
if not found
|
boolean |
hasWeakKeys()
Tells if this WeakHashClock has Weak keys
|
private DoubleNode<K,V> |
moveDot() |
private DoubleNode<K,V> |
moveDotNoWeak() |
java.util.Map.Entry<K,V> |
next()
Returns the next key/value pair in the clock,
or null if the clock has no members.
|
void |
put(K key,
V value)
Adds the given pair to the clock.
|
void |
releaseMatching(CacheKeyFilter<K> filter)
Releases all key/value pairs that match the filter
|
V |
remove(K key)
Removes the given key from the clock, if found
|
private void |
removeFromDLL(DoubleNode<K,V> removeMe) |
private void |
removeStale() |
int |
size()
Returns the number of elements currently
in the clock.
|
java.lang.String |
toString() |
private final boolean isWeak
private final java.util.concurrent.ConcurrentHashMap<K,DoubleNode<K,V>> byKeyNotWeak
private final java.util.WeakHashMap<K,DoubleNode<K,V>> byKey
private final java.lang.ref.ReferenceQueue<? super K> myQueue
private DoubleNode<K,V> head
private DoubleNode<K,V> tail
private DoubleNode<K,V> dot
private DoubleNode<K,V> addBeforeDot(K key, V value)
private void removeFromDLL(DoubleNode<K,V> removeMe)
public void put(K key, V value)
WeakHashClock
put
in interface WeakHashClock<K,V>
key
- Must not be nullvalue
- May not be nullpublic V get(K key)
WeakHashClock
get
in interface WeakHashClock<K,V>
key
- The key to search for, may not be nullpublic V remove(K key)
WeakHashClock
remove
in interface WeakHashClock<K,V>
key
- The key to remove, may not be nullpublic void releaseMatching(CacheKeyFilter<K> filter)
WeakHashClock
releaseMatching
in interface WeakHashClock<K,V>
filter
- A non-null filter that can be used
to delete every key/value pair that matches the filterpublic int size()
WeakHashClock
size
in interface WeakHashClock<K,V>
private DoubleNode<K,V> moveDot()
private DoubleNode<K,V> moveDotNoWeak()
public java.util.Map.Entry<K,V> next()
WeakHashClock
next
in interface WeakHashClock<K,V>
public void clear()
WeakHashClock
clear
in interface WeakHashClock<K,V>
public void clearStaleReferences()
WeakHashClock
clearStaleReferences
in interface WeakHashClock<K,V>
private void removeStale()
public boolean hasWeakKeys()
WeakHashClock
hasWeakKeys
in interface WeakHashClock<K,V>
public java.lang.String toString()
toString
in class java.lang.Object