|
Build 1.0_r1(from source) | |||||||||
| 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>
java.util.concurrent.CopyOnWriteArraySet<E>
E - the type of elements held in this collectionpublic class CopyOnWriteArraySet<E>
A Set that uses CopyOnWriteArrayList for all of its
operations. Thus, it shares the same basic properties:
Sample Usage. Probably the main application of copy-on-write sets are classes that maintain sets of Handler objects that must be multicasted to upon an update command. This is a classic case where you do not want to be holding a lock while sending a message, and where traversals normally vastly overwhelm additions.
class Handler { void handle(); ... }
class X {
private final CopyOnWriteArraySet<Handler> handlers = new CopyOnWriteArraySet<Handler>();
public void addHandler(Handler h) { handlers.add(h); }
private long internalState;
private synchronized void changeState() { internalState = ...; }
public void update() {
changeState();
Iterator it = handlers.iterator();
while (it.hasNext())
it.next().handle();
}
}
CopyOnWriteArrayList,
Serialized Form| Constructor Summary | |
|---|---|
CopyOnWriteArraySet()
Creates an empty set. |
|
CopyOnWriteArraySet(Collection<? extends E> c)
Creates a set containing all of the elements of the specified Collection. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E o)
If the specified element is not contained within this collection, and addition of this element succeeds, then true will be returned. |
|
boolean |
addAll(Collection<? extends E> c)
Adds the objects in the specified Collection to this Collection. |
|
void |
clear()
Removes all the elements in this collection. |
|
boolean |
contains(Object o)
Searches this Collection for the specified object. |
|
boolean |
containsAll(Collection<?> c)
Searches this Collection for all objects in the specified Collection. |
|
boolean |
isEmpty()
Returns true if the collection has no element, otherwise false. |
|
Iterator<E> |
iterator()
Returns an Iterator on the elements of this Collection. |
|
boolean |
remove(Object o)
Removes the first occurrence of the specified object from this Collection. |
|
boolean |
removeAll(Collection<?> c)
Removes all occurrences in this Collection of each object in the specified Collection. |
|
boolean |
retainAll(Collection<?> c)
Removes all objects from this Collection that are not contained in the specified Collection. |
|
int |
size()
Returns the number of elements in this Collection. |
|
Object[] |
toArray()
Returns a new array containing all elements contained in this Collection. |
|
|
toArray(T[] a)
Returns an array containing all elements contained in this Collection. |
|
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode |
| Methods inherited from class java.util.AbstractCollection |
|---|
toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CopyOnWriteArraySet()
public CopyOnWriteArraySet(Collection<? extends E> c)
c - the collection| Method Detail |
|---|
public int size()
AbstractCollection
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean isEmpty()
AbstractCollection
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>Collection.size()public boolean contains(Object o)
AbstractCollection
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>o - the object to search for
object is an element of this Collection,
false otherwisepublic Object[] toArray()
AbstractCollection
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] a)
AbstractCollection
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>a - the array
public void clear()
AbstractCollection
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>Collection.isEmpty(),
Collection.size()public Iterator<E> iterator()
AbstractCollection
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>iterator in class AbstractCollection<E>Iteratorpublic boolean remove(Object o)
AbstractCollection
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>o - the object to remove
public boolean add(E o)
AbstractCollection
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>o - the element to be added.
public boolean containsAll(Collection<?> c)
AbstractCollection
containsAll in interface Collection<E>containsAll in interface Set<E>containsAll in class AbstractCollection<E>c - the Collection of objects
public boolean addAll(Collection<? extends E> c)
AbstractCollection
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>c - the Collection of objects
public boolean removeAll(Collection<?> c)
AbstractSet
removeAll in interface Collection<E>removeAll in interface Set<E>removeAll in class AbstractSet<E>c - the Collection of objects to remove
public boolean retainAll(Collection<?> c)
AbstractCollection
retainAll in interface Collection<E>retainAll in interface Set<E>retainAll in class AbstractCollection<E>c - the Collection of objects to retain
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||