Module org.glassfish.hk2.utilities
Class WeakHashLRUImpl<K>
java.lang.Object
org.glassfish.hk2.utilities.general.internal.WeakHashLRUImpl<K>
- All Implemented Interfaces:
WeakHashLRU<K>
An implementation of the WeakHashLRU as needed by the CAR algorithm
- Author:
- jwells
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given key to the LRU.voidclear()Removes all entries from this LRUvoidCauses stale references to be cleared from the data structures.booleanTells if the given key is in the LRUvoidreleaseMatching(CacheKeyFilter<K> filter) Releases all keys that match the filterremove()Removes the key that was Least Recently UsedbooleanRemoves the given key from the LRU, if foundintsize()Returns the number of elements currently in the clock.toString()
-
Constructor Details
-
WeakHashLRUImpl
public WeakHashLRUImpl(boolean isWeak)
-
-
Method Details
-
add
Description copied from interface:WeakHashLRUAdds the given key to the LRU. It will be placed at the MRU of the LRU. If this key already exists in the LRU it will be moved to the MRU- Specified by:
addin interfaceWeakHashLRU<K>- Parameters:
key- Must not be null
-
contains
Description copied from interface:WeakHashLRUTells if the given key is in the LRU- Specified by:
containsin interfaceWeakHashLRU<K>- Parameters:
key- The key to search for, may not be null- Returns:
- true if found, false otherwise
-
remove
Description copied from interface:WeakHashLRURemoves the given key from the LRU, if found- Specified by:
removein interfaceWeakHashLRU<K>- Parameters:
key- The key to remove, may not be null- Returns:
- true if removed, false otherwise
-
size
public int size()Description copied from interface:WeakHashLRUReturns the number of elements currently in the clock. References that have gone away because they were weakly referenced will not be counted in the size- Specified by:
sizein interfaceWeakHashLRU<K>- Returns:
- The number of entries currently in the LRU
-
remove
Description copied from interface:WeakHashLRURemoves the key that was Least Recently Used- Specified by:
removein interfaceWeakHashLRU<K>- Returns:
- The key that was removed, or null if the list is empty
-
releaseMatching
Description copied from interface:WeakHashLRUReleases all keys that match the filter- Specified by:
releaseMatchingin interfaceWeakHashLRU<K>- Parameters:
filter- A non-null filter that can be used to delete every key that matches the filter
-
clear
public void clear()Description copied from interface:WeakHashLRURemoves all entries from this LRU- Specified by:
clearin interfaceWeakHashLRU<K>
-
clearStaleReferences
public void clearStaleReferences()Description copied from interface:WeakHashLRUCauses stale references to be cleared from the data structures. Since this is a weak clock the references can go away at any time, which happens whenever any operation has been performed. However, it may be the case that no operation will be performed for a while and so this method is provided to have a no-op operation to call in order to clear out any stale references- Specified by:
clearStaleReferencesin interfaceWeakHashLRU<K>
-
toString
-