|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Object | +--org.apache.commons.collections.DefaultMapBag
This class provides a skeletal implementation of the Bag
interface to minimize the effort required for target implementations.
Subclasses need only to call setMap(Map) in their constructor
specifying a map instance that will be used to store the contents of
the bag.
| Constructor Summary | |
DefaultMapBag()
|
|
| 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 |
addAll(Collection c)
|
protected int |
calcTotalSize()
Actually walks the bag to make sure the count is correct and resets the running total |
void |
clear()
|
boolean |
contains(Object o)
|
boolean |
containsAll(Bag other)
Returns true if the bag contains all elements in
the given collection, respecting cardinality. |
boolean |
containsAll(Collection c)
Returns true if the bag contains all elements in
the given collection, respecting cardinality. |
boolean |
equals(Object o)
|
int |
getCount(Object o)
Return the number of occurrences (cardinality) of the given object currently in the bag. |
protected Map |
getMap()
Utility method for implementations to access the map that backs this bag. |
int |
hashCode()
|
boolean |
isEmpty()
|
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(Bag other)
Remove any members of the bag that are not in the given bag, respecting cardinality. |
boolean |
retainAll(Collection c)
Remove any members of the bag that are not in the given collection, respecting cardinality. |
protected void |
setMap(Map m)
Utility method for implementations to set the map that backs this bag. |
int |
size()
Returns the total number of items in the bag across all types. |
Object[] |
toArray()
|
Object[] |
toArray(Object[] a)
|
Set |
uniqueSet()
The Set of unique members that represent all members in
the bag. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DefaultMapBag()
| Method Detail |
public boolean add(Object o)
BagBag.uniqueSet() then increment its count as
reported by Bag.getCount(Object). Otherwise add it to the Bag.uniqueSet() and report its count as 1.add in interface Bagorg.apache.commons.collections.Bagtrue if the object was not already in the
uniqueSetBag.getCount(Object)
public boolean add(Object o,
int i)
Bagi copies of the given object to the bag and
keep a count.add in interface Bagorg.apache.commons.collections.Bagtrue if the object was not already in the
uniqueSetBag.add(Object),
Bag.getCount(Object)public boolean addAll(Collection c)
addAll in interface Collectionprotected int calcTotalSize()
public void clear()
clear in interface Collectionpublic boolean contains(Object o)
contains in interface Collectionpublic boolean containsAll(Bag other)
true if the bag contains all elements in
the given collection, respecting cardinality.containsAll(Collection)public boolean containsAll(Collection c)
Bagtrue 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 Bag.getCount(Object) on that object must
be >= n for all n in C.containsAll in interface Bagpublic boolean equals(Object o)
equals in interface Collectionequals in class Objectpublic int getCount(Object o)
BaggetCount in interface Bagprotected Map getMap()
public int hashCode()
hashCode in interface CollectionhashCode in class Objectpublic boolean isEmpty()
isEmpty in interface Collectionpublic Iterator iterator()
BagIterator 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 Bagpublic boolean remove(Object o)
BagBag.uniqueSet().remove in interface Bagorg.apache.commons.collections.Bagtrue if this call changed the collectionBag.remove(Object, int)
public boolean remove(Object o,
int i)
Bagi occurrences or less, the item will be
removed from the Bag.uniqueSet().remove in interface Bagorg.apache.commons.collections.Bagtrue if this call changed the collectionBag.getCount(Object),
Bag.remove(Object)public boolean removeAll(Collection c)
BagC 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 Bagorg.apache.commons.collections.Bagtrue if this call changed the collectionpublic boolean retainAll(Bag other)
true if this call changed the collectionretainAll(Collection)public boolean retainAll(Collection c)
BagC 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 Bagorg.apache.commons.collections.Bagtrue if this call changed the collectionprotected void setMap(Map m)
public int size()
Bagsize in interface Bagpublic Object[] toArray()
toArray in interface Collectionpublic Object[] toArray(Object[] a)
toArray in interface Collectionpublic Set uniqueSet()
BagSet of unique members that represent all members in
the bag. Uniqueness constraints are the same as those in Set.uniqueSet in interface Bag
|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||