public class SynchronizedCollection extends Object implements Collection, Serializable
Collection to synchronize its behaviour
for a multi-threaded environment.
Iterators must be manually synchronized:
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Field and Description |
|---|---|
protected Collection |
collection
The collection to decorate
|
protected Object |
lock
The object to lock on, needed for List/SortedSet views
|
| Modifier | Constructor and Description |
|---|---|
protected |
SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
|
protected |
SynchronizedCollection(Collection collection,
Object lock)
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Object object) |
boolean |
addAll(Collection coll) |
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection coll) |
static Collection |
decorate(Collection coll)
Factory method to create a synchronized collection.
|
boolean |
equals(Object object) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator |
iterator()
Iterators must be manually synchronized.
|
boolean |
remove(Object object) |
boolean |
removeAll(Collection coll) |
boolean |
retainAll(Collection coll) |
int |
size() |
Object[] |
toArray() |
Object[] |
toArray(Object[] object) |
String |
toString() |
protected final Collection collection
protected final Object lock
protected SynchronizedCollection(Collection collection)
collection - the collection to decorate, must not be nullIllegalArgumentException - if the collection is nullprotected SynchronizedCollection(Collection collection, Object lock)
collection - the collection to decorate, must not be nulllock - the lock object to use, must not be nullIllegalArgumentException - if the collection is nullpublic static Collection decorate(Collection coll)
coll - the collection to decorate, must not be nullIllegalArgumentException - if collection is nullpublic boolean add(Object object)
add in interface Collectionpublic boolean addAll(Collection coll)
addAll in interface Collectionpublic void clear()
clear in interface Collectionpublic boolean contains(Object object)
contains in interface Collectionpublic boolean containsAll(Collection coll)
containsAll in interface Collectionpublic boolean isEmpty()
isEmpty in interface Collectionpublic Iterator iterator()
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}iterator in interface Iterableiterator in interface Collectionpublic Object[] toArray()
toArray in interface Collectionpublic Object[] toArray(Object[] object)
toArray in interface Collectionpublic boolean remove(Object object)
remove in interface Collectionpublic boolean removeAll(Collection coll)
removeAll in interface Collectionpublic boolean retainAll(Collection coll)
retainAll in interface Collectionpublic int size()
size in interface Collectionpublic boolean equals(Object object)
equals in interface Collectionequals in class Objectpublic int hashCode()
hashCode in interface CollectionhashCode in class ObjectCopyright © 2001–2015 The Apache Software Foundation. All rights reserved.