Class SynchronizedCollection<E>
java.lang.Object
org.apache.commons.collections4.collection.SynchronizedCollection<E>
- Type Parameters:
- E- the type of the elements in the collection
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>
- Direct Known Subclasses:
- SynchronizedBag,- SynchronizedMultiSet,- SynchronizedQueue
Decorates another 
Collection to synchronize its behavior
 for a multithreaded 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:
- 3.0
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSynchronizedCollection(Collection<E> collection) Constructor that wraps (not copies).protectedSynchronizedCollection(Collection<E> collection, Object lock) Constructor that wraps (not copies).
- 
Method SummaryModifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> coll) voidclear()booleanbooleancontainsAll(Collection<?> coll) protected Collection<E> Gets the collection being decorated.booleaninthashCode()booleanisEmpty()iterator()Iterators must be manually synchronized.booleanbooleanremoveAll(Collection<?> coll) booleanbooleanretainAll(Collection<?> coll) intsize()static <T> SynchronizedCollection<T> synchronizedCollection(Collection<T> coll) Factory method to create a synchronized collection.Object[]toArray()<T> T[]toArray(T[] object) toString()Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, spliterator, stream
- 
Field Details- 
lock
 
- 
- 
Constructor Details- 
SynchronizedCollectionConstructor that wraps (not copies).- Parameters:
- collection- the collection to decorate, must not be null
- Throws:
- NullPointerException- if the collection is null
 
- 
SynchronizedCollectionConstructor that wraps (not copies).- Parameters:
- collection- the collection to decorate, must not be null
- lock- the lock object to use, must not be null
- Throws:
- NullPointerException- if the collection or lock is null
 
 
- 
- 
Method Details- 
synchronizedCollectionFactory method to create a synchronized collection.- Type Parameters:
- T- the type of the elements in the collection
- Parameters:
- coll- the collection to decorate, must not be null
- Returns:
- a new synchronized collection
- Throws:
- NullPointerException- if collection is null
- Since:
- 4.0
 
- 
add- Specified by:
- addin interface- Collection<E>
 
- 
addAll- Specified by:
- addAllin interface- Collection<E>
 
- 
clear- Specified by:
- clearin interface- Collection<E>
 
- 
contains- Specified by:
- containsin interface- Collection<E>
 
- 
containsAll- Specified by:
- containsAllin interface- Collection<E>
 
- 
decoratedGets the collection being decorated.- Returns:
- the decorated collection
 
- 
equals
- 
hashCode
- 
isEmpty- Specified by:
- isEmptyin interface- Collection<E>
 
- 
iteratorIterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
- 
remove- Specified by:
- removein interface- Collection<E>
 
- 
removeAll- Specified by:
- removeAllin interface- Collection<E>
 
- 
removeIf
- 
retainAll- Specified by:
- retainAllin interface- Collection<E>
 
- 
size- Specified by:
- sizein interface- Collection<E>
 
- 
toArray- Specified by:
- toArrayin interface- Collection<E>
 
- 
toArray- Specified by:
- toArrayin interface- Collection<E>
 
- 
toString
 
-