org.apache.commons.collections.bag

Class SynchronizedBag

public class SynchronizedBag extends SynchronizedCollection implements Bag

Decorates another Bag to synchronize its behaviour for a multi-threaded environment.

Methods are synchronized, then forwarded to the decorated bag. Iterators must be separately synchronized around the loop.

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

Constructor Summary
protected SynchronizedBag(Bag bag)
Constructor that wraps (not copies).
protected SynchronizedBag(Bag bag, Object lock)
Constructor that wraps (not copies).
Method Summary
booleanadd(Object object, int count)
static Bagdecorate(Bag bag)
Factory method to create a synchronized bag.
protected BaggetBag()
Gets the bag being decorated.
intgetCount(Object object)
booleanremove(Object object, int count)
SetuniqueSet()

Constructor Detail

SynchronizedBag

protected SynchronizedBag(Bag bag)
Constructor that wraps (not copies).

Parameters: bag the bag to decorate, must not be null

Throws: IllegalArgumentException if bag is null

SynchronizedBag

protected SynchronizedBag(Bag bag, Object lock)
Constructor that wraps (not copies).

Parameters: bag the bag to decorate, must not be null lock the lock to use, must not be null

Throws: IllegalArgumentException if bag is null

Method Detail

add

public boolean add(Object object, int count)

decorate

public static Bag decorate(Bag bag)
Factory method to create a synchronized bag.

Parameters: bag the bag to decorate, must not be null

Returns: a new synchronized Bag

Throws: IllegalArgumentException if bag is null

getBag

protected Bag getBag()
Gets the bag being decorated.

Returns: the decorated bag

getCount

public int getCount(Object object)

remove

public boolean remove(Object object, int count)

uniqueSet

public Set uniqueSet()
Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.