Bag to comply with the Collection contract.
By decorating an existing Bag instance with a CollectionBag,
it can be safely passed on to methods that require Collection types that
are fully compliant with the Collection contract.
The method javadoc highlights the differences compared to the original Bag interface.
Bag
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides org. |
| Access | Constructor and Description |
|---|---|
| public | CollectionBag(final Bag<E>
the bag to decorate, must not be null bag)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true, alwaysthe object to add object)Overrides org. Implements org. |
| public boolean | Returns: true, alwaysthe object to add object, final int the number of copies to add count)Overrides org. Implements org. count copies of the specified object to the Bag.
|
| public boolean | addAll(final Collection<? extends E>
collection containing elements to be added to this collection coll)Overrides org. Implements java. |
| public static < the type of the elements in the bag E> Bag | Returns: a Bag that complies to the Collection contractthe bag to decorate, must not be null bag)Factory method to create a bag that complies to the Collection contract. |
| public boolean | Returns: true if the Bag contains at least one of every object in the collectionthe collection to check against coll)Overrides org. Implements org. true if the bag contains all elements in
the given collection, not respecting cardinality.
|
| private void | readObject(final ObjectInputStream
the input stream in)Read the collection in using a custom routine. |
| public boolean | Returns: true if this call changed the collectionthe object to remove object)Overrides org. Implements org. |
| public boolean | Returns: true if this call changed the collectionthe collection to remove coll)Overrides org. Implements org. |
| public boolean | Returns: true if this call changed the collectionthe collection to retain coll)Overrides org. Implements org. |
| private void | writeObject(final ObjectOutputStream
the output stream out)Write the collection out using a custom routine. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Serialization version | |
| CollectionBag | back to summary |
|---|---|
| public CollectionBag(final Bag<E> bag) Constructor that wraps (not copies).
| |
| add | back to summary |
|---|---|
| public boolean add(final E object) Overrides org. Implements org. (Change) Adds one copy of the specified object to the Bag.
Since this method always increases the size of the bag, it
will always return
| |
| add | back to summary |
|---|---|
| public boolean add(final E object, final int count) Overrides org. Implements org. (Change)
Adds
Since this method always increases the size of the bag, it
will always return
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(final Collection<? extends E> coll) Overrides org. Implements java. Doc from java. Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.
| |
| collectionBag | back to summary |
|---|---|
| public static <E> Bag Factory method to create a bag that complies to the Collection contract.
| |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(final Collection<?> coll) Overrides org. Implements org. (Change)
Returns
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the collection in using a custom routine.
| |
| remove | back to summary |
|---|---|
| public boolean remove(final Object object) Overrides org. Implements org. (Change) Removes the first occurrence of the given object from the bag.
This will also remove the object from the | |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(final Collection<?> coll) Overrides org. Implements org. (Change) Remove all elements represented in the given collection, not respecting cardinality. That is, remove all occurrences of every object contained in the given collection.
| |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(final Collection<?> coll) Overrides org. Implements org. (Change)
Remove any members of the bag that are not in the given collection,
not respecting cardinality. That is, any object in the given
collection
This implementation iterates over the elements of this bag, checking
each element in turn to see if it's contained in
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the collection out using a custom routine.
| |