|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--org.apache.commons.collections.collection.SynchronizedCollection
Decorates another 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.
| Field Summary | |
protected Collection |
collection
The collection to decorate |
protected Object |
lock
The object to lock on, needed for List/SortedSet views |
| Constructor Summary | |
protected |
SynchronizedCollection(Collection collection)
Constructor that wraps (not copies). |
protected |
SynchronizedCollection(Collection collection,
Object lock)
Constructor that wraps (not copies). |
| Method Summary | |
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()
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected final Collection collection
protected final Object lock
| Constructor Detail |
protected SynchronizedCollection(Collection collection)
collection - the collection to decorate, must not be null
IllegalArgumentException - if the collection is null
protected SynchronizedCollection(Collection collection,
Object lock)
collection - the collection to decorate, must not be nulllock - the lock object to use, must not be null
IllegalArgumentException - if the collection is null| Method Detail |
public static Collection decorate(Collection coll)
coll - the collection to decorate, must not be null
IllegalArgumentException - 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 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 Objectpublic String toString()
toString in class Object
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||