|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
bb.util.ConcurrentHashSet<E>
E
- Type of element stored in the setpublic class ConcurrentHashSet<E>
Set implementation backed by a concurrent hash table (a ConcurrentHashMap
instance).
This class is to be used precisely in those situations where CopyOnWriteArraySet
has issues:
Because it uses a backing ConcurrentHashMap instance, this class does not permit the null element.
This class offers constant time performance for the basic operations
(add
, remove
, contains
and size
),
assuming that the hash function disperses the elements properly among the buckets.
Iterating over this set requires time proportional to the sum of the ConcurrentHashSet instance's size (the number of elements) plus the "capacity" of the backing ConcurrentHashMap instance (the number of buckets). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important. Note that this class makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
This class is thread safe, and offers the same full concurrency of retrievals, adjustable expected concurrency for updates, and iterator behavior as ConcurrentHashMap.
Field Summary | |
---|---|
private ConcurrentHashMap<E,Object> |
map
|
private static Object |
present
Dummy value to associate with an Object in the backing Map. |
(package private) static long |
serialVersionUID
|
Constructor Summary | |
---|---|
ConcurrentHashSet()
Constructs a new empty set. |
|
ConcurrentHashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection. |
|
ConcurrentHashSet(int initialCapacity)
Constructs a new empty set. |
|
ConcurrentHashSet(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Constructs a new, empty set. |
Method Summary | |
---|---|
boolean |
add(E o)
|
void |
clear()
|
boolean |
contains(Object o)
|
boolean |
isEmpty()
|
Iterator<E> |
iterator()
Returns an Iterator over the elements in this set. |
boolean |
remove(Object o)
|
int |
size()
|
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, retainAll, toArray, toArray |
Field Detail |
---|
static final long serialVersionUID
private static final Object present
private final ConcurrentHashMap<E,Object> map
Constructor Detail |
---|
public ConcurrentHashSet()
public ConcurrentHashSet(int initialCapacity) throws IllegalArgumentException
initialCapacity
- the initial capacity of the hash table
IllegalArgumentException
- if initialCapacity < 0public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) throws IllegalArgumentException
initialCapacity
- the initial capacity of the hash maploadFactor
- the load factor of the hash mapconcurrencyLevel
- the concurrency level of the hash map
IllegalArgumentException
- if initialCapacity < 0; loadFactor <= 0; concurrencyLevel <= 0public ConcurrentHashSet(Collection<? extends E> c) throws IllegalArgumentException
c
- the collection whose elements are to be placed into this set
IllegalArgumentException
- if c == nullMethod Detail |
---|
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
public boolean add(E o)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public Iterator<E> iterator()
Iterator
over the elements in this set.
The elements are returned in no particular order.
The result supports Iterator.remove
.
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
iterator
in class AbstractCollection<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |