Class SynchronizedCollection
java.lang.Object
org.apache.commons.collections.collection.SynchronizedCollection
- All Implemented Interfaces:
 Serializable,Iterable,Collection
- Direct Known Subclasses:
 SynchronizedBag,SynchronizedBuffer,SynchronizedList,SynchronizedSet,SynchronizedSortedSet
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.
- Since:
 - Commons Collections 3.0
 - Version:
 - $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
 - Author:
 - Stephen Colebourne
 - See Also:
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CollectionThe collection to decorateprotected final ObjectThe object to lock on, needed for List/SortedSet views - 
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSynchronizedCollection(Collection collection) Constructor that wraps (not copies).protectedSynchronizedCollection(Collection collection, Object lock) Constructor that wraps (not copies). - 
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection coll) voidclear()booleanbooleancontainsAll(Collection coll) static Collectiondecorate(Collection coll) Factory method to create a synchronized collection.booleaninthashCode()booleanisEmpty()iterator()Iterators must be manually synchronized.booleanbooleanremoveAll(Collection coll) booleanretainAll(Collection coll) intsize()Object[]toArray()Object[]toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray 
- 
Field Details
- 
collection
The collection to decorate - 
lock
The object to lock on, needed for List/SortedSet views 
 - 
 - 
Constructor Details
- 
SynchronizedCollection
Constructor that wraps (not copies).- Parameters:
 collection- the collection to decorate, must not be null- Throws:
 IllegalArgumentException- if the collection is null
 - 
SynchronizedCollection
Constructor that wraps (not copies).- Parameters:
 collection- the collection to decorate, must not be nulllock- the lock object to use, must not be null- Throws:
 IllegalArgumentException- if the collection is null
 
 - 
 - 
Method Details
- 
decorate
Factory method to create a synchronized collection.- Parameters:
 coll- the collection to decorate, must not be null- Returns:
 - a new synchronized collection
 - Throws:
 IllegalArgumentException- if collection is null
 - 
add
- Specified by:
 addin interfaceCollection
 - 
addAll
- Specified by:
 addAllin interfaceCollection
 - 
clear
public void clear()- Specified by:
 clearin interfaceCollection
 - 
contains
- Specified by:
 containsin interfaceCollection
 - 
containsAll
- Specified by:
 containsAllin interfaceCollection
 - 
isEmpty
public boolean isEmpty()- Specified by:
 isEmptyin interfaceCollection
 - 
iterator
Iterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }- Specified by:
 iteratorin interfaceCollection- Specified by:
 iteratorin interfaceIterable- Returns:
 - an iterator that must be manually synchronized on the collection
 
 - 
toArray
- Specified by:
 toArrayin interfaceCollection
 - 
toArray
- Specified by:
 toArrayin interfaceCollection
 - 
remove
- Specified by:
 removein interfaceCollection
 - 
removeAll
- Specified by:
 removeAllin interfaceCollection
 - 
retainAll
- Specified by:
 retainAllin interfaceCollection
 - 
size
public int size()- Specified by:
 sizein interfaceCollection
 - 
equals
- Specified by:
 equalsin interfaceCollection- Overrides:
 equalsin classObject
 - 
hashCode
public int hashCode()- Specified by:
 hashCodein interfaceCollection- Overrides:
 hashCodein classObject
 - 
toString
 
 -