Class WeakConcurrentMap<K,V>
java.lang.Object
java.lang.ref.ReferenceQueue<K>
org.mockito.internal.util.concurrent.WeakConcurrentMap<K,V>
- Direct Known Subclasses:
WeakConcurrentMap.WithInlinedExpunction
public class WeakConcurrentMap<K,V>
extends ReferenceQueue<K>
implements Runnable, Iterable<Map.Entry<K,V>>
A thread-safe map with weak keys. Entries are based on a key's system hash code and keys are considered equal only by reference equality.
This class does not implement theMap interface because this implementation is incompatible
with the map contract. While iterating over a map's entries, any key that has not passed iteration is referenced non-weakly.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate static classprivate classprivate static classstatic classAWeakConcurrentMapwhere stale entries are removed as a side effect of interacting with this map. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicLongfinal ConcurrentMap<WeakConcurrentMap.WeakKey<K>, V> private final Thread -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the approximate size of this map where the returned number is at least as big as the actual number of entries.voidclear()Clears the entire map.booleancontainsKey(K key) protected VdefaultValue(K key) Creates a default value.voidCleans all unused references.iterator()voidrun()Methods inherited from class ReferenceQueue
poll, remove, removeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
ID
-
target
-
thread
-
-
Constructor Details
-
WeakConcurrentMap
public WeakConcurrentMap(boolean cleanerThread) - Parameters:
cleanerThread-trueif a thread should be started that removes stale entries.
-
-
Method Details
-
get
-
containsKey
- Parameters:
key- The key of the entry.- Returns:
trueif the key already defines a value.
-
put
-
remove
-
clear
public void clear()Clears the entire map. -
defaultValue
Creates a default value. There is no guarantee that the requested value will be set as a once it is created in case that another thread requests a value for a key concurrently.- Parameters:
key- The key for which to create a default value.- Returns:
- The default value for a key without value or
nullfor not defining a default value.
-
getCleanerThread
- Returns:
- The cleaner thread or
nullif no such thread was set.
-
expungeStaleEntries
public void expungeStaleEntries()Cleans all unused references. -
approximateSize
public int approximateSize()Returns the approximate size of this map where the returned number is at least as big as the actual number of entries.- Returns:
- The minimum size of this map.
-
run
-
iterator
-