boolean | add(Object object) (Violation) Adds one copy the specified object to the Bag. |
boolean | add(Object object, int nCopies) Adds nCopies copies of the specified object to the Bag. |
boolean | containsAll(Collection coll) (Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality. |
int | getCount(Object object) Returns the number of occurrences (cardinality) of the given object currently in the bag. |
Iterator | iterator() Returns an Iterator over the entire set of members, including copies due to cardinality. |
boolean | remove(Object object) (Violation) Removes all occurrences of the given object from the bag. |
boolean | remove(Object object, int nCopies) Removes nCopies copies of the specified object from the Bag. |
boolean | removeAll(Collection coll) (Violation) Remove all elements represented in the given collection, respecting cardinality. |
boolean | retainAll(Collection coll) (Violation) Remove any members of the bag that are not in the given collection, respecting cardinality. |
int | size() Returns the total number of items in the bag across all types. |
Set | Returns a Set of unique elements in the Bag. |
public boolean add(Object object, int nCopies)
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
.
public boolean add(Object object)
true
. Since it sometimes returns
false
, this method violates the contract. A future
version of this method will comply by always returning true
.
public boolean containsAll(Collection coll)
true
if the bag contains all elements in
the given collection, respecting cardinality. That is, if the
given collection coll
contains n
copies
of a given object, calling getCount(Object) on that object must
be >= n
for all n
in coll
.
The Collection.containsAll(Collection) method specifies
that cardinality should not be respected; this method should
return true if the bag contains at least one of every object contained
in the given collection. A future version of this method will comply
with that contract.
public int getCount(Object object)
public Iterator iterator()
public boolean remove(Object object, int nCopies)
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.
public boolean remove(Object object)
public boolean removeAll(Collection coll)
coll
contains n
copies of a given object,
the bag will have n
fewer copies, assuming the bag
had at least n
copies to begin with.
The Collection.removeAll(Collection) method specifies
that cardinality should not be respected; this method should
remove all occurrences of every object contained in the
given collection. A future version of this method will comply
with that contract.
public boolean retainAll(Collection coll)
coll
contains n
copies of a
given object and the bag has m > n
copies, then
delete m - n
copies from the bag. In addition, if
e
is an object in the bag but
!coll.contains(e)
, then remove e
and any
of its copies.
The Collection.retainAll(Collection) method specifies
that cardinality should not be respected; this method should
keep all occurrences of every object contained in the
given collection. A future version of this method will comply
with that contract.
public int size()
public Set uniqueSet()
{a, a, b, c}
. Calling getCount(Object) ona
would return 2, while calling uniqueSet() would return{a, b, c}
. Note that this interface violates the Collection contract. The behavior specified in many of these methods is not the same as the behavior specified byCollection
. The noncompliant methods are clearly marked with "(Violation)". A future version of this class will specify the same behavior asCollection
, which unfortunately will break backwards compatibility with this version.