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.predicatedBag(new HashBag(), NotNullPredicate.INSTANCE);
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides org. |
| Access | Constructor and Description |
|---|---|
| protected | PredicatedBag(final Bag<E>
the bag to decorate, must not be null bag, final Predicate<? super E> the predicate to use for validation, must not be null predicate)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(final E
the object to add object, final int the number of copies to add count)Implements org. nCopies copies of the specified object to the Bag.
|
| protected Bag | Returns: the decorated bagOverrides org. |
| public boolean | equals(final Object
object to be compared for equality with this collection object)Overrides java. Implements java. |
| public int | getCount(final Object
the object to search for object)Implements org. |
| public int | hashCode()
Overrides java. Implements java. |
| public static < the type of the elements in the bag E> PredicatedBag | Returns: a new predicated Bagthe bag to decorate, must not be null bag, final Predicate<? super E> the predicate to use for validation, must not be null predicate)Factory method to create a predicated (validating) bag. |
| public boolean | remove(final Object
the object to remove object, final int the number of copies to remove count)Implements org. nCopies copies of the specified object from the Bag.
|
| public Set | uniqueSet()
Implements org. Set of unique elements in the Bag.
|
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Serialization version | |
| PredicatedBag | back to summary |
|---|---|
| protected PredicatedBag(final Bag<E> bag, final Predicate<? super E> predicate) Constructor that wraps (not copies). If there are any elements already in the bag being decorated, they are validated.
| |
| add | back to summary |
|---|---|
| public boolean add(final E object, final int count) Implements org. Doc from org. Adds
If the object is already in the
| |
| decorated | back to summary |
|---|---|
| protected Bag Overrides org. Gets the decorated bag. | |
| equals | back to summary |
|---|---|
| public boolean equals(final Object object) Overrides java. Implements java. Doc from java. Compares the specified object with this collection for equality.
While the
The general contract for the | |
| getCount | back to summary |
|---|---|
| public int getCount(final Object object) Implements org. Doc from org. 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. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this collection. While the
| |
| predicatedBag | back to summary |
|---|---|
| public static <E> PredicatedBag Factory method to create a predicated (validating) bag. If there are any elements already in the bag being decorated, they are validated.
| |
| remove | back to summary |
|---|---|
| public boolean remove(final Object object, final int count) Implements org. Doc from org. Removes If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown. | |
| uniqueSet | back to summary |
|---|---|
| public Set Implements org. Doc from org. Returns a
Uniqueness constraints are the same as those in | |