java.lang.Object | ||||
↳ | org.apache.commons.collections.collection.AbstractCollectionDecorator | |||
↳ | org.apache.commons.collections.collection.AbstractSerializableCollectionDecorator | |||
↳ | org.apache.commons.collections.collection.PredicatedCollection | |||
↳ | org.apache.commons.collections.bag.PredicatedBag |
Known Direct Subclasses |
Decorates another Bag
to validate that additions
match a specified predicate.
This bag exists to provide validation for the decorated bag. It is normally created to decorate an empty bag. If an object cannot be added to the bag, an IllegalArgumentException is thrown.
One usage would be to ensure that no null entries are added to the bag.
Bag bag = PredicatedBag.decorate(new HashBag(), NotNullPredicate.INSTANCE);
This class is Serializable from Commons Collections 3.1.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.collection.PredicatedCollection
| |||||||||||
From class
org.apache.commons.collections.collection.AbstractCollectionDecorator
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that wraps (not copies).
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds
nCopies copies of the specified object to the Bag. | |||||||||||
Factory method to create a predicated (validating) bag.
| |||||||||||
Returns the number of occurrences (cardinality) of the given
object currently in the bag.
| |||||||||||
Removes
nCopies copies of the specified object from the Bag. | |||||||||||
Returns a
Set of unique elements in the Bag. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the decorated bag.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.collection.PredicatedCollection
| |||||||||||
From class
org.apache.commons.collections.collection.AbstractCollectionDecorator
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Iterable
| |||||||||||
From interface
java.util.Collection
| |||||||||||
From interface
org.apache.commons.collections.Bag
|
Constructor that wraps (not copies).
If there are any elements already in the bag being decorated, they are validated.
bag | the bag to decorate, must not be null |
---|---|
predicate | the predicate to use for validation, must not be null |
IllegalArgumentException | if bag or predicate is null |
---|---|
IllegalArgumentException | if the bag contains invalid elements |
Adds nCopies
copies of the specified object to the Bag.
If the object is already in the uniqueSet()
then increment its
count as reported by getCount(Object)
. Otherwise add it to the
uniqueSet()
and report its count as nCopies
.
object | the object to add |
---|---|
count | the number of copies to add |
true
if the object was not already in the uniqueSet
Factory method to create a predicated (validating) bag.
If there are any elements already in the bag being decorated, they are validated.
bag | the bag to decorate, must not be null |
---|---|
predicate | the predicate to use for validation, must not be null |
IllegalArgumentException | if bag or predicate is null |
---|---|
IllegalArgumentException | if the bag contains invalid elements |
Returns the number of occurrences (cardinality) of the given object currently in the bag. If the object does not exist in the bag, return 0.
object | the object to search for |
---|
Removes nCopies
copies of the specified object from the Bag.
If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.
object | the object to remove |
---|---|
count | the number of copies to remove |
true
if this call changed the collection