org.apache.commons.collections.collection
Class SynchronizedCollection
java.lang.Object
|
+--org.apache.commons.collections.collection.SynchronizedCollection
- All Implemented Interfaces:
- Collection
- Direct Known Subclasses:
- SynchronizedBag, SynchronizedBuffer, SynchronizedList, SynchronizedSet, SynchronizedSortedSet
- public class SynchronizedCollection
- extends Object
- implements Collection
Decorates another 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
}
- Since:
- Commons Collections 3.0
- Version:
- $Revision: 1.3 $ $Date: 2004/01/14 21:43:18 $
- Author:
- Stephen Colebourne
collection
protected final Collection collection
- The collection to decorate
lock
protected final Object lock
- The object to lock on, needed for List/SortedSet views
SynchronizedCollection
protected SynchronizedCollection(Collection collection)
- Constructor that wraps (not copies).
- Parameters:
collection
- the collection to decorate, must not be null- Throws:
IllegalArgumentException
- if the collection is null
SynchronizedCollection
protected SynchronizedCollection(Collection collection,
Object lock)
- Constructor that wraps (not copies).
- Parameters:
collection
- the collection to decorate, must not be nulllock
- the lock object to use, must not be null- Throws:
IllegalArgumentException
- if the collection is null
decorate
public static Collection decorate(Collection coll)
- Factory method to create a synchronized collection.
- Parameters:
coll
- the collection to decorate, must not be null- Throws:
IllegalArgumentException
- if collection is null
add
public boolean add(Object object)
- Specified by:
add
in interface Collection
addAll
public boolean addAll(Collection coll)
- Specified by:
addAll
in interface Collection
clear
public void clear()
- Specified by:
clear
in interface Collection
contains
public boolean contains(Object object)
- Specified by:
contains
in interface Collection
containsAll
public boolean containsAll(Collection coll)
- Specified by:
containsAll
in interface Collection
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface Collection
iterator
public Iterator iterator()
- Iterators must be manually synchronized.
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}
- Specified by:
iterator
in interface Collection
- Returns:
- an iterator that must be manually synchronized on the collection
toArray
public Object[] toArray()
- Specified by:
toArray
in interface Collection
toArray
public Object[] toArray(Object[] object)
- Specified by:
toArray
in interface Collection
remove
public boolean remove(Object object)
- Specified by:
remove
in interface Collection
removeAll
public boolean removeAll(Collection coll)
- Specified by:
removeAll
in interface Collection
retainAll
public boolean retainAll(Collection coll)
- Specified by:
retainAll
in interface Collection
size
public int size()
- Specified by:
size
in interface Collection
equals
public boolean equals(Object object)
- Specified by:
equals
in interface Collection
- Overrides:
equals
in class Object
hashCode
public int hashCode()
- Specified by:
hashCode
in interface Collection
- Overrides:
hashCode
in class Object
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2001-2004 Apache Software Foundation. All Rights Reserved.