Suppose you have a Bag that contains {a, a, b, c}.
Calling getCount(Object) on a would return 2, while
calling uniqueSet() would return {a, b, c}.
NOTE: This interface violates the Collection contract.
The behavior specified in many of these methods is not the same
as the behavior specified by Collection.
The noncompliant methods are clearly marked with "(Violation)".
Exercise caution when using a bag as a Collection.
This violation resulted from the original specification of this interface. In an ideal world, the interface would be changed to fix the problems, however it has been decided to maintain backwards compatibility instead.
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the object was not already in the uniqueSetthe object to add object)Redeclares java. |
| public boolean | Returns: true if the object was not already in the uniqueSetthe object to add object, int the number of copies to add nCopies)Adds |
| public boolean | Returns: true if the Bag contains all the collectionthe collection to check against coll)Redeclares java. true if the bag contains all elements in
the given collection, respecting cardinality.
|
| public int | |
| public Iterator | Returns: iterator over all elements in the BagRedeclares java. Iterator over the entire set of members,
including copies due to cardinality.
|
| public boolean | Returns: true if this call changed the collectionthe object to remove object)Redeclares java. |
| public boolean | |
| public boolean | Returns: true if this call changed the collectionthe collection to remove coll)Redeclares java. |
| public boolean | Returns: true if this call changed the collectionthe collection to retain coll)Redeclares java. |
| public int | Returns: the total size of the BagRedeclares java. |
| public Set |
| add | back to summary |
|---|---|
| public boolean add(E object) Redeclares java. (Violation) Adds one copy of the specified object to the Bag.
If the object is already in the
Since this method always increases the size of the bag,
according to the
| |
| add | back to summary |
|---|---|
| public boolean add(E object, int nCopies) Adds
If the object is already in the
| |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(Collection<?> coll) Redeclares java. (Violation)
Returns
The
| |
| getCount | back to summary |
|---|---|
| public int getCount(Object object) 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.
| |
| iterator | back to summary |
|---|---|
| public Iterator Redeclares java. Returns an | |
| remove | back to summary |
|---|---|
| public boolean remove(Object object) Redeclares java. (Violation) Removes all occurrences of the given object from the bag.
This will also remove the object from the
According to the | |
| remove | back to summary |
|---|---|
| public boolean remove(Object object, int nCopies) Removes If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.
| |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(Collection<?> coll) Redeclares java. (Violation)
Remove all elements represented in the given collection,
respecting cardinality. That is, if the given collection
The
| |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(Collection<?> coll) Redeclares java. (Violation)
Remove any members of the bag that are not in the given
collection, respecting cardinality. That is, if the given
collection
The
| |
| size | back to summary |
|---|---|
| public int size() Redeclares java. Returns the total number of items in the bag across all types.
| |
| uniqueSet | back to summary |
|---|---|
| public Set Returns a
Uniqueness constraints are the same as those in
| |