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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSynchronizedCollection(Collection<E> collection) Constructs and wraps (not copies).protectedSynchronizedCollection(Collection<E> collection, Object lock) Constructs and wraps (not copies). -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> coll) voidclear()booleanbooleancontainsAll(Collection<?> coll) protected Collection<E> Gets the collection being decorated.booleanvoidinthashCode()booleanisEmpty()iterator()Iterators must be manually synchronized.booleanbooleanremoveAll(Collection<?> coll) booleanbooleanretainAll(Collection<?> coll) intsize()static <T> SynchronizedCollection<T> synchronizedCollection(Collection<T> coll) Creates a synchronized collection.Object[]toArray()<T> T[]toArray(T[] object) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, spliterator, stream
-
Field Details
-
lock
The object to lock on, needed for List/SortedSet views
-
-
Constructor Details
-
SynchronizedCollection
Constructs and wraps (not copies).- Parameters:
collection- The collection to decorate, must not be null.- Throws:
NullPointerException- if the collection is null.
-
SynchronizedCollection
Constructs and 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
-
synchronizedCollection
Creates 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 interfaceCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>
-
clear
- Specified by:
clearin interfaceCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>
-
decorated
Gets the collection being decorated.- Returns:
- The decorated collection.
-
equals
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
forEach
-
hashCode
- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
isEmpty
- Specified by:
isEmptyin interfaceCollection<E>
-
iterator
Iterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator } -
remove
- Specified by:
removein interfaceCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>
-
removeIf
- Specified by:
removeIfin interfaceCollection<E>- Since:
- 4.4
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>
-
size
- Specified by:
sizein interfaceCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toString
-