|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.collections.AbstractBag
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 | |
AbstractBag()
|
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 AbstractBag()
Method Detail |
public boolean add(Object o)
Bag
Bag.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 Bag
org.apache.commons.collections.Bag
true
if the object was not already in the
uniqueSet
Bag.getCount(Object)
public boolean add(Object o, int i)
Bag
i
copies of the given object to the bag and
keep a count.add
in interface Bag
org.apache.commons.collections.Bag
true
if the object was not already in the
uniqueSet
Bag.add(Object)
,
Bag.getCount(Object)
public boolean addAll(Collection c)
addAll
in interface Collection
protected int calcTotalSize()
public void clear()
clear
in interface Collection
public boolean contains(Object o)
contains
in interface Collection
public boolean containsAll(Bag other)
true
if the bag contains all elements in
the given collection, respecting cardinality.containsAll(Collection)
public boolean containsAll(Collection c)
Bag
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 Bag.getCount(Object)
on that object must
be >= n
for all n
in C
.containsAll
in interface Bag
public boolean equals(Object o)
equals
in interface Collection
equals
in class Object
public int getCount(Object o)
Bag
getCount
in interface Bag
protected Map getMap()
public int hashCode()
hashCode
in interface Collection
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection
public Iterator iterator()
Bag
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 Bag
public boolean remove(Object o)
Bag
Bag.uniqueSet()
.remove
in interface Bag
org.apache.commons.collections.Bag
true
if this call changed the collectionBag.remove(Object, int)
public boolean remove(Object o, int i)
Bag
i
occurrences or less, the item will be
removed from the Bag.uniqueSet()
.remove
in interface Bag
org.apache.commons.collections.Bag
true
if this call changed the collectionBag.getCount(Object)
,
Bag.remove(Object)
public boolean removeAll(Collection c)
Bag
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 Bag
org.apache.commons.collections.Bag
true
if this call changed the collectionpublic boolean retainAll(Bag other)
true
if this call changed the collectionretainAll(Collection)
public boolean retainAll(Collection c)
Bag
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 Bag
org.apache.commons.collections.Bag
true
if this call changed the collectionprotected void setMap(Map m)
public int size()
Bag
size
in interface Bag
public Object[] toArray()
toArray
in interface Collection
public Object[] toArray(Object[] a)
toArray
in interface Collection
public Set uniqueSet()
Bag
Set
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 |