org.apache.commons.collections.bag

Class SynchronizedBag

Implemented Interfaces:
Bag, Collection, Serializable
Known Direct Subclasses:
SynchronizedSortedBag

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.

Version:
$Revision: 1.8 $ $Date: 2004/06/03 22:02:12 $
Author:
Stephen Colebourne
Since:
Commons Collections 3.0

Field Summary

Fields inherited from class org.apache.commons.collections.collection.SynchronizedCollection

collection, lock

Constructor Summary

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

Method Summary

boolean
add(Object object, int count)
static Bag
decorate(Bag bag)
Factory method to create a synchronized bag.
protected Bag
getBag()
Gets the bag being decorated.
int
getCount(Object object)
boolean
remove(Object object, int count)
Set
uniqueSet()

Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection

add, addAll, clear, contains, containsAll, decorate, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString

Constructor Details

SynchronizedBag

protected SynchronizedBag(Bag bag)
Constructor that wraps (not copies).
Parameters:
bag - the bag to decorate, must not be 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

Method Details

add

public boolean add(Object object,
                   int count)
Specified by:
add in interface Bag

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

getBag

protected Bag getBag()
Gets the bag being decorated.
Returns:
the decorated bag

getCount

public int getCount(Object object)
Specified by:
getCount in interface Bag

remove

public boolean remove(Object object,
                      int count)
Specified by:
remove in interface Bag

uniqueSet

public Set uniqueSet()
Specified by:
uniqueSet in interface Bag

Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.