E
- the type of the elements in the collectionpublic class SynchronizedCollection<E> extends Object implements Collection<E>, Serializable
Collection
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.
Modifier and Type | Field and Description |
---|---|
protected Object |
lock
The object to lock on, needed for List/SortedSet views
|
Modifier | Constructor and Description |
---|---|
protected |
SynchronizedCollection(Collection<E> collection)
Constructor that wraps (not copies).
|
protected |
SynchronizedCollection(Collection<E> collection,
Object lock)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object) |
boolean |
addAll(Collection<? extends E> coll) |
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection<?> coll) |
protected Collection<E> |
decorated()
Gets the collection being decorated.
|
boolean |
equals(Object object) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator()
Iterators must be manually synchronized.
|
boolean |
remove(Object object) |
boolean |
removeAll(Collection<?> coll) |
boolean |
retainAll(Collection<?> coll) |
int |
size() |
static <T> SynchronizedCollection<T> |
synchronizedCollection(Collection<T> coll)
Factory method to create a synchronized collection.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] object) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parallelStream, removeIf, spliterator, stream
protected SynchronizedCollection(Collection<E> collection)
collection
- the collection to decorate, must not be nullNullPointerException
- if the collection is nullprotected SynchronizedCollection(Collection<E> collection, Object lock)
collection
- the collection to decorate, must not be nulllock
- the lock object to use, must not be nullNullPointerException
- if the collection or lock is nullpublic static <T> SynchronizedCollection<T> synchronizedCollection(Collection<T> coll)
T
- the type of the elements in the collectioncoll
- the collection to decorate, must not be nullNullPointerException
- if collection is nullprotected Collection<E> decorated()
public boolean add(E object)
add
in interface Collection<E>
public boolean addAll(Collection<? extends E> coll)
addAll
in interface Collection<E>
public void clear()
clear
in interface Collection<E>
public boolean contains(Object object)
contains
in interface Collection<E>
public boolean containsAll(Collection<?> coll)
containsAll
in interface Collection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
public Iterator<E> iterator()
synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
public Object[] toArray()
toArray
in interface Collection<E>
public <T> T[] toArray(T[] object)
toArray
in interface Collection<E>
public boolean remove(Object object)
remove
in interface Collection<E>
public boolean removeAll(Collection<?> coll)
removeAll
in interface Collection<E>
public boolean retainAll(Collection<?> coll)
retainAll
in interface Collection<E>
public int size()
size
in interface Collection<E>
public boolean equals(Object object)
equals
in interface Collection<E>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in class Object
Copyright © 2001–2018 The Apache Software Foundation. All rights reserved.