Package zombie.core.Collections
Class NonBlockingHashSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
zombie.core.Collections.NonBlockingHashSet<E>
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
A simple wrapper around
NonBlockingHashMap
making it implement the
Set
interface. All operations are Non-Blocking and multi-thread safe.- Since:
- 1.5
- See Also:
-
Constructor Summary
-
Method Summary
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
NonBlockingHashSet
public NonBlockingHashSet()Make a new emptyNonBlockingHashSet
.
-
-
Method Details
-
add
Addo
to the set.- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
- Returns:
- true if
o
was added to the set, false ifo
was already in the set.
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
- Returns:
- true if
o
is in the set.
-
remove
Removeo
from the set.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
- Returns:
- true if
o
was removed to the set, false ifo
was not in the set.
-
size
public int size()Current count of elements in the set. Due to concurrent racing updates, the size is only ever approximate. Updates due to the calling thread are immediately visible to calling thread.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
- Returns:
- count of elements.
-
clear
public void clear()Empty the set.- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
iterator
-
readOnly
public void readOnly()Atomically make the set immutable. Future calls to mutate will throw an IllegalStateException. Existing mutator calls in other threads racing with this thread and will either throw IllegalStateException or their update will be visible to this thread. This implies that a simple flag cannot make the Set immutable, because a late-arriving update in another thread might see immutable flag not set yet, then mutate the Set after thereadOnly()
call returns. This call can be called concurrently (and indeed until the operation completes, all calls on the Set from any thread either complete normally or end up callingreadOnly()
internally).This call is useful in debugging multi-threaded programs where the Set is constructed in parallel, but construction completes after some time; and after construction the Set is only read. Making the Set read-only will cause updates arriving after construction is supposedly complete to throw an
IllegalStateException
.
-