public class SynchronizedCollection extends Object implements Collection, 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 Collection |
collection
The collection to decorate
|
protected Object |
lock
The object to lock on, needed for List/SortedSet views
|
Modifier | Constructor and Description |
---|---|
protected |
SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
|
protected |
SynchronizedCollection(Collection collection,
Object lock)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object object) |
boolean |
addAll(Collection coll) |
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection coll) |
static Collection |
decorate(Collection coll)
Factory method to create a synchronized collection.
|
boolean |
equals(Object object) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator |
iterator()
Iterators must be manually synchronized.
|
boolean |
remove(Object object) |
boolean |
removeAll(Collection coll) |
boolean |
retainAll(Collection coll) |
int |
size() |
Object[] |
toArray() |
Object[] |
toArray(Object[] object) |
String |
toString() |
protected final Collection collection
protected final Object lock
protected SynchronizedCollection(Collection collection)
collection
- the collection to decorate, must not be nullIllegalArgumentException
- if the collection is nullprotected SynchronizedCollection(Collection collection, Object lock)
collection
- the collection to decorate, must not be nulllock
- the lock object to use, must not be nullIllegalArgumentException
- if the collection is nullpublic static Collection decorate(Collection coll)
coll
- the collection to decorate, must not be nullIllegalArgumentException
- if collection is nullpublic boolean add(Object object)
add
in interface Collection
public boolean addAll(Collection coll)
addAll
in interface Collection
public void clear()
clear
in interface Collection
public boolean contains(Object object)
contains
in interface Collection
public boolean containsAll(Collection coll)
containsAll
in interface Collection
public boolean isEmpty()
isEmpty
in interface Collection
public Iterator iterator()
synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
iterator
in interface Iterable
iterator
in interface Collection
public Object[] toArray()
toArray
in interface Collection
public Object[] toArray(Object[] object)
toArray
in interface Collection
public boolean remove(Object object)
remove
in interface Collection
public boolean removeAll(Collection coll)
removeAll
in interface Collection
public boolean retainAll(Collection coll)
retainAll
in interface Collection
public int size()
size
in interface Collection
public boolean equals(Object object)
equals
in interface Collection
equals
in class Object
public int hashCode()
hashCode
in interface Collection
hashCode
in class Object
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.