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
public class SynchronizedCollection<E> extends Object implements Collection<E>, Serializable
Decorates anotherCollectionto 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:
- 3.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E object)booleanaddAll(Collection<? extends E> coll)voidclear()booleancontains(Object object)booleancontainsAll(Collection<?> coll)booleanequals(Object object)inthashCode()booleanisEmpty()Iterator<E>iterator()Iterators must be manually synchronized.booleanremove(Object object)booleanremoveAll(Collection<?> coll)booleanremoveIf(Predicate<? super E> filter)booleanretainAll(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)StringtoString()-
Methods inherited from interface java.util.Collection
parallelStream, spliterator, stream, toArray
-
-
-
-
Method Detail
-
synchronizedCollection
public static <T> SynchronizedCollection<T> synchronizedCollection(Collection<T> coll)
Factory 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
public boolean add(E object)
- Specified by:
addin interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> coll)
- Specified by:
addAllin interfaceCollection<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>
-
contains
public boolean contains(Object object)
- Specified by:
containsin interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> coll)
- Specified by:
containsAllin interfaceCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>
-
iterator
public Iterator<E> iterator()
Iterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] object)
- Specified by:
toArrayin interfaceCollection<E>
-
remove
public boolean remove(Object object)
- Specified by:
removein interfaceCollection<E>
-
removeIf
public boolean removeIf(Predicate<? super E> filter)
- Specified by:
removeIfin interfaceCollection<E>- Since:
- 4.4
-
removeAll
public boolean removeAll(Collection<?> coll)
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> coll)
- Specified by:
retainAllin interfaceCollection<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>
-
equals
public boolean equals(Object object)
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
-