⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.collection

Class SynchronizedCollection

java.lang.Object
|
+--org.apache.commons.collections.collection.SynchronizedCollection

All Implemented Interfaces:
Collection

Known Direct Subclasses:
SynchronizedBag, SynchronizedBuffer, SynchronizedList, SynchronizedSet, SynchronizedSortedSet


public class SynchronizedCollection
extends java.lang.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
Author:
Stephen Colebourne

Field Summary

Collection

collection

The collection to decorate

Object

lock

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

Constructor Summary

SynchronizedCollection(Collection collection)

Constructor that wraps (not copies).

SynchronizedCollection(Collection collection, Object lock)

Constructor that wraps (not copies).

Method Summary

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()

Field Details

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 Details

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:
- if the collection is null

SynchronizedCollection

protected SynchronizedCollection(Collection collection)

Constructor that wraps (not copies).

Parameters:
collection - the collection to decorate, must not be null
Throws:
- if the collection is null

Method Details

add

public boolean add(Object object)

Parameters:
object

addAll

public boolean addAll(Collection coll)

Parameters:
coll

clear

public void clear()


contains

public boolean contains(Object object)

Parameters:
object

containsAll

public boolean containsAll(Collection coll)

Parameters:
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
Throws:
- if collection is null

equals

public boolean equals(Object object)

Parameters:
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)

Parameters:
object

removeAll

public boolean removeAll(Collection coll)

Parameters:
coll

retainAll

public boolean retainAll(Collection coll)

Parameters:
coll

size

public int size()


toArray

public Object[] toArray()


toArray

public Object[] toArray(Object[] object)

Parameters:
object

toString

public String toString()