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:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>
- Direct Known Subclasses:
SynchronizedBag,SynchronizedMultiSet,SynchronizedQueue
public class SynchronizedCollection<E> extends java.lang.Object implements java.util.Collection<E>, java.io.SerializableDecorates 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(java.util.Collection<? extends E> coll)voidclear()booleancontains(java.lang.Object object)booleancontainsAll(java.util.Collection<?> coll)booleanequals(java.lang.Object object)inthashCode()booleanisEmpty()java.util.Iterator<E>iterator()Iterators must be manually synchronized.booleanremove(java.lang.Object object)booleanremoveAll(java.util.Collection<?> coll)booleanremoveIf(java.util.function.Predicate<? super E> filter)booleanretainAll(java.util.Collection<?> coll)intsize()static <T> SynchronizedCollection<T>synchronizedCollection(java.util.Collection<T> coll)Factory method to create a synchronized collection.java.lang.Object[]toArray()<T> T[]toArray(T[] object)java.lang.StringtoString()
-
-
-
Method Detail
-
synchronizedCollection
public static <T> SynchronizedCollection<T> synchronizedCollection(java.util.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:
java.lang.NullPointerException- if collection is null- Since:
- 4.0
-
addAll
public boolean addAll(java.util.Collection<? extends E> coll)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object object)
- Specified by:
containsin interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> coll)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
Iterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] object)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
remove
public boolean remove(java.lang.Object object)
- Specified by:
removein interfacejava.util.Collection<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIfin interfacejava.util.Collection<E>- Since:
- 4.4
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>
-
equals
public boolean equals(java.lang.Object object)
- Specified by:
equalsin interfacejava.util.Collection<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<E>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-