Class WeakConcurrentSet<V>
- java.lang.Object
-
- org.mockito.internal.util.concurrent.WeakConcurrentSet<V>
-
- All Implemented Interfaces:
java.lang.Iterable<V>,java.lang.Runnable
public class WeakConcurrentSet<V> extends java.lang.Object implements java.lang.Runnable, java.lang.Iterable<V>A thread-safe set with weak values. Entries are based on a key's system hash code and keys are considered equal only by reference equality.
This class does not implement theSetinterface because this implementation is incompatible with the set contract. While iterating over a set's entries, any value that has not passed iteration is referenced non-weakly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWeakConcurrentSet.CleanerDetermines the cleaning format.private static classWeakConcurrentSet.ReducingIterator<V>
-
Field Summary
Fields Modifier and Type Field Description (package private) WeakConcurrentMap<V,java.lang.Boolean>target
-
Constructor Summary
Constructors Constructor Description WeakConcurrentSet(WeakConcurrentSet.Cleaner cleaner)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(V value)intapproximateSize()Returns the approximate size of this set where the returned number is at least as big as the actual number of entries.voidclear()Clears the set.booleancontains(V value)voidexpungeStaleEntries()Cleans all unused references.java.lang.ThreadgetCleanerThread()java.util.Iterator<V>iterator()booleanremove(V value)voidrun()
-
-
-
Field Detail
-
target
final WeakConcurrentMap<V,java.lang.Boolean> target
-
-
Constructor Detail
-
WeakConcurrentSet
public WeakConcurrentSet(WeakConcurrentSet.Cleaner cleaner)
-
-
Method Detail
-
add
public boolean add(V value)
- Parameters:
value- The value to add to the set.- Returns:
trueif the value was added to the set and was not contained before.
-
contains
public boolean contains(V value)
- Parameters:
value- The value to check if it is contained in the set.- Returns:
trueif the set contains the value.
-
remove
public boolean remove(V value)
- Parameters:
value- The value to remove from the set.- Returns:
trueif the value is contained in the set.
-
clear
public void clear()
Clears the set.
-
approximateSize
public int approximateSize()
Returns the approximate size of this set where the returned number is at least as big as the actual number of entries.- Returns:
- The minimum size of this set.
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
expungeStaleEntries
public void expungeStaleEntries()
Cleans all unused references.
-
getCleanerThread
public java.lang.Thread getCleanerThread()
- Returns:
- The cleaner thread or
nullif no such thread was set.
-
-