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 theSet
interface 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.Modifier and Type | Class and Description |
---|---|
static class |
WeakConcurrentSet.Cleaner
Determines the cleaning format.
|
private static class |
WeakConcurrentSet.ReducingIterator<V> |
Modifier and Type | Field and Description |
---|---|
(package private) WeakConcurrentMap<V,java.lang.Boolean> |
target |
Constructor and Description |
---|
WeakConcurrentSet(WeakConcurrentSet.Cleaner cleaner) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(V value) |
int |
approximateSize()
Returns the approximate size of this set where the returned number is at least as big as the actual number of entries.
|
void |
clear()
Clears the set.
|
boolean |
contains(V value) |
void |
expungeStaleEntries()
Cleans all unused references.
|
java.lang.Thread |
getCleanerThread() |
java.util.Iterator<V> |
iterator() |
boolean |
remove(V value) |
void |
run() |
final WeakConcurrentMap<V,java.lang.Boolean> target
public WeakConcurrentSet(WeakConcurrentSet.Cleaner cleaner)
public boolean add(V value)
value
- The value to add to the set.true
if the value was added to the set and was not contained before.public boolean contains(V value)
value
- The value to check if it is contained in the set.true
if the set contains the value.public boolean remove(V value)
value
- The value to remove from the set.true
if the value is contained in the set.public void clear()
public int approximateSize()
public void run()
run
in interface java.lang.Runnable
public void expungeStaleEntries()
public java.lang.Thread getCleanerThread()
null
if no such thread was set.