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

Class PredicatedBag

java.lang.Object
|
+--org.apache.commons.collections.collection.AbstractCollectionDecorator
   |
   +--org.apache.commons.collections.collection.PredicatedCollection
      |
      +--org.apache.commons.collections.bag.PredicatedBag

All Implemented Interfaces:
Collection, Bag

Known Direct Subclasses:
PredicatedSortedBag


public class PredicatedBag
extends PredicatedCollection
implements Bag

Decorates another Bag to validate that additions match a specified predicate.

If an object cannot be added to the list, an IllegalArgumentException is thrown.

Since:
Commons Collections 3.0
Authors:
Stephen Colebourne
Paul Jack

Constructor Summary

PredicatedBag(Bag bag, Predicate predicate)

Constructor that wraps (not copies).

Method Summary

boolean

add(Object object, int count)

static Bag

decorate(Bag bag, Predicate predicate)

Factory method to create a predicated (validating) bag.

Bag

getBag()

Gets the decorated bag.

int

getCount(Object object)

boolean

remove(Object object, int count)

Set

uniqueSet()

Constructor Details

PredicatedBag

protected PredicatedBag(Bag bag, Predicate predicate)

Constructor that wraps (not copies).

If there are any elements already in the bag being decorated, they are validated.

Parameters:
bag - the bag to decorate, must not be null
predicate - the predicate to use for validation, must not be null
Throws:
- if bag or predicate is null
- if the bag contains invalid elements

Method Details

add

public boolean add(Object object, int count)

Parameters:
object
count

decorate

public static Bag decorate(Bag bag, Predicate predicate)

Factory method to create a predicated (validating) bag.

If there are any elements already in the bag being decorated, they are validated.

Parameters:
bag - the bag to decorate, must not be null
predicate - the predicate to use for validation, must not be null
Throws:
- if bag or predicate is null
- if the bag contains invalid elements

getBag

protected Bag getBag()

Gets the decorated bag.

Returns:
the decorated bag

getCount

public int getCount(Object object)

Parameters:
object

remove

public boolean remove(Object object, int count)

Parameters:
object
count

uniqueSet

public Set uniqueSet()