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

Class SynchronizedBag

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

All Implemented Interfaces:
Collection, Bag

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.

Since:
Commons Collections 3.0
Author:
Stephen Colebourne

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.

Bag

getBag()

int

getCount(Object object)

boolean

remove(Object object, int count)

Set

uniqueSet()

Constructor Details

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

SynchronizedBag

protected SynchronizedBag(Bag bag)

Constructor that wraps (not copies).

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

Method Details

add

public boolean add(Object object, int count)

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

getBag

protected Bag getBag()


getCount

public int getCount(Object object)

Parameters:
object

remove

public boolean remove(Object object, int count)

Parameters:
object
count

uniqueSet

public Set uniqueSet()