Package net.engio.mbassy.common
Class AbstractConcurrentSet<T>
- java.lang.Object
-
- net.engio.mbassy.common.AbstractConcurrentSet<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.Set<T>
- Direct Known Subclasses:
StrongConcurrentSet
,WeakConcurrentSet
public abstract class AbstractConcurrentSet<T> extends java.lang.Object implements java.util.Set<T>
This data structure is optimized for non-blocking reads even when write operations occur. Running read iterators will not be affected by add operations since writes always insert at the head of the structure. Remove operations can affect any running iterator such that a removed element that has not yet been reached by the iterator will not appear in that iterator anymore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractConcurrentSet.Entry<T>
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConcurrentSet(java.util.Map<T,ISetEntry<T>> entries)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
add(T element)
boolean
addAll(java.util.Collection<? extends T> elements)
void
clear()
boolean
contains(java.lang.Object element)
boolean
containsAll(java.util.Collection<?> c)
protected abstract AbstractConcurrentSet.Entry<T>
createEntry(T value, AbstractConcurrentSet.Entry<T> next)
boolean
equals(java.lang.Object obj)
int
hashCode()
private boolean
insert(T element)
Inserts a new element at the head of the set.boolean
isEmpty()
boolean
remove(java.lang.Object element)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
int
size()
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
-
-
-
Field Detail
-
id
private static final java.util.concurrent.atomic.AtomicLong id
-
ID
private final long ID
-
lock
protected final java.util.concurrent.locks.ReentrantReadWriteLock lock
-
head
protected AbstractConcurrentSet.Entry<T> head
-
-
Method Detail
-
createEntry
protected abstract AbstractConcurrentSet.Entry<T> createEntry(T value, AbstractConcurrentSet.Entry<T> next)
-
add
public boolean add(T element)
-
contains
public boolean contains(java.lang.Object element)
-
insert
private boolean insert(T element)
Inserts a new element at the head of the set. Note: This method is expected to be synchronized by the calling code
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
addAll
public boolean addAll(java.util.Collection<? extends T> elements)
-
remove
public boolean remove(java.lang.Object element)
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
clear
public void clear()
-
hashCode
public int hashCode()
-
-