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.Serializable
Decorates anotherCollection
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:
- 3.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E object)
boolean
addAll(java.util.Collection<? extends E> coll)
void
clear()
boolean
contains(java.lang.Object object)
boolean
containsAll(java.util.Collection<?> coll)
boolean
equals(java.lang.Object object)
int
hashCode()
boolean
isEmpty()
java.util.Iterator<E>
iterator()
Iterators must be manually synchronized.boolean
remove(java.lang.Object object)
boolean
removeAll(java.util.Collection<?> coll)
boolean
removeIf(java.util.function.Predicate<? super E> filter)
boolean
retainAll(java.util.Collection<?> coll)
int
size()
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.String
toString()
-
-
-
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:
addAll
in interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object object)
- Specified by:
contains
in interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> coll)
- Specified by:
containsAll
in interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in 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:
toArray
in interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] object)
- Specified by:
toArray
in interfacejava.util.Collection<E>
-
remove
public boolean remove(java.lang.Object object)
- Specified by:
remove
in interfacejava.util.Collection<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIf
in interfacejava.util.Collection<E>
- Since:
- 4.4
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
- Specified by:
removeAll
in interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
- Specified by:
retainAll
in interfacejava.util.Collection<E>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<E>
-
equals
public boolean equals(java.lang.Object object)
- Specified by:
equals
in interfacejava.util.Collection<E>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<E>
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-