|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A Collection
that counts the number of times an object appears in
the collection. 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}
.
Method Summary | |
boolean |
add(Object o)
Add the given object to the bag and keep a count. |
boolean |
add(Object o,
int i)
Add i copies of the given object to the bag and
keep a count. |
boolean |
containsAll(Collection c)
Returns true if the bag contains all elements in
the given collection, respecting cardinality. |
int |
getCount(Object o)
Return 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 o)
Remove all occurrences of the given object from the bag, and do not represent the object in the uniqueSet() . |
boolean |
remove(Object o,
int i)
Remove the given number of occurrences from the bag. |
boolean |
removeAll(Collection c)
Remove all elements represented in the given collection, respecting cardinality. |
boolean |
retainAll(Collection c)
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 |
uniqueSet()
The Set of unique members that represent all members in
the bag. |
Methods inherited from interface java.util.Collection |
addAll, clear, contains, equals, hashCode, isEmpty, toArray, toArray |
Method Detail |
public boolean add(Object o)
uniqueSet()
then increment its count as
reported by getCount(Object)
. Otherwise add it to the uniqueSet()
and report its count as 1.add
in interface Collection
true
if the object was not already in the
uniqueSet
getCount(Object)
public boolean add(Object o, int i)
i
copies of the given object to the bag and
keep a count.true
if the object was not already in the
uniqueSet
add(Object)
,
getCount(Object)
public boolean containsAll(Collection c)
true
if the bag contains all elements in
the given collection, respecting cardinality. That is, if the
given collection C
contains n
copies
of a given object, calling getCount(Object)
on that object must
be >= n
for all n
in C
.containsAll
in interface Collection
public int getCount(Object o)
public Iterator iterator()
Iterator
over the entire set of members,
including copies due to cardinality. This iterator is fail-fast
and will not tolerate concurrent modifications.iterator
in interface Collection
public boolean remove(Object o)
uniqueSet()
.remove
in interface Collection
true
if this call changed the collectionremove(Object, int)
public boolean remove(Object o, int i)
i
occurrences or less, the item will be
removed from the uniqueSet()
.true
if this call changed the collectiongetCount(Object)
,
remove(Object)
public boolean removeAll(Collection c)
C
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.removeAll
in interface Collection
true
if this call changed the collectionpublic boolean retainAll(Collection c)
C
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
!C.contains(e)
, then remove e
and any
of its copies.retainAll
in interface Collection
true
if this call changed the collectionpublic int size()
size
in interface Collection
public Set uniqueSet()
Set
of unique members that represent all members in
the bag. Uniqueness constraints are the same as those in Set
.
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |