org.apache.commons.collections.collection

Class SynchronizedCollection

public class SynchronizedCollection extends Object implements Collection, Serializable

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
 }
 

This class is Serializable from Commons Collections 3.1.

Since: Commons Collections 3.0

Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $

Author: Stephen Colebourne

Field Summary
protected Collectioncollection
The collection to decorate
protected Objectlock
The object to lock on, needed for List/SortedSet views
Constructor Summary
protected SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
protected SynchronizedCollection(Collection collection, Object lock)
Constructor that wraps (not copies).
Method Summary
booleanadd(Object object)
booleanaddAll(Collection coll)
voidclear()
booleancontains(Object object)
booleancontainsAll(Collection coll)
static Collectiondecorate(Collection coll)
Factory method to create a synchronized collection.
booleanequals(Object object)
inthashCode()
booleanisEmpty()
Iteratoriterator()
Iterators must be manually synchronized.
booleanremove(Object object)
booleanremoveAll(Collection coll)
booleanretainAll(Collection coll)
intsize()
Object[]toArray()
Object[]toArray(Object[] object)
StringtoString()

Field Detail

collection

protected final Collection collection
The collection to decorate

lock

protected final Object lock
The object to lock on, needed for List/SortedSet views

Constructor Detail

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 null lock the lock object to use, must not be null

Throws: IllegalArgumentException if the collection is null

Method Detail

add

public boolean add(Object object)

addAll

public boolean addAll(Collection coll)

clear

public void clear()

contains

public boolean contains(Object object)

containsAll

public boolean containsAll(Collection coll)

decorate

public static Collection decorate(Collection coll)
Factory method to create a synchronized collection.

Parameters: coll the collection to decorate, must not be null

Returns: a new synchronized collection

Throws: IllegalArgumentException if collection is null

equals

public boolean equals(Object object)

hashCode

public int hashCode()

isEmpty

public boolean isEmpty()

iterator

public Iterator iterator()
Iterators must be manually synchronized.
 synchronized (coll) {
   Iterator it = coll.iterator();
   // do stuff with iterator
 }

Returns: an iterator that must be manually synchronized on the collection

remove

public boolean remove(Object object)

removeAll

public boolean removeAll(Collection coll)

retainAll

public boolean retainAll(Collection coll)

size

public int size()

toArray

public Object[] toArray()

toArray

public Object[] toArray(Object[] object)

toString

public String toString()
Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.