|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections.DefaultMapBag
public abstract class DefaultMapBag
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
(or invoke the Map constructor) specifying a map instance that will be used
to store the contents of the bag.
The map will be used to map bag elements to a number; the number represents the number of occurrences of that element in the bag.
| Constructor Summary | |
|---|---|
|
DefaultMapBag()
Deprecated. No-argument constructor. |
protected |
DefaultMapBag(java.util.Map map)
Deprecated. Constructor that assigns the specified Map as the backing store. |
| Method Summary | |
|---|---|
boolean |
add(java.lang.Object object)
Deprecated. Adds a new element to the bag by incrementing its count in the underlying map. |
boolean |
add(java.lang.Object object,
int nCopies)
Deprecated. Adds a new element to the bag by incrementing its count in the map. |
boolean |
addAll(java.util.Collection coll)
Deprecated. Invokes add(Object) for each element in the given collection. |
protected int |
calcTotalSize()
Deprecated. Actually walks the bag to make sure the count is correct and resets the running total |
void |
clear()
Deprecated. Clears the bag by clearing the underlying map. |
boolean |
contains(java.lang.Object object)
Deprecated. Determines if the bag contains the given element by checking if the underlying map contains the element as a key. |
boolean |
containsAll(Bag other)
Deprecated. Returns true if the bag contains all elements in
the given collection, respecting cardinality. |
boolean |
containsAll(java.util.Collection coll)
Deprecated. Determines if the bag contains the given elements. |
boolean |
equals(java.lang.Object object)
Deprecated. Returns true if the given object is not null, has the precise type of this bag, and contains the same number of occurrences of all the same elements. |
int |
getCount(java.lang.Object object)
Deprecated. Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. |
protected java.util.Map |
getMap()
Deprecated. Utility method for implementations to access the map that backs this bag. |
int |
hashCode()
Deprecated. Returns the hash code of the underlying map. |
boolean |
isEmpty()
Deprecated. Returns true if the underlying map is empty. |
java.util.Iterator |
iterator()
Deprecated. Returns an Iterator over the entire set of members,
including copies due to cardinality. |
boolean |
remove(java.lang.Object object)
Deprecated. (Violation) Removes all occurrences of the given object from the bag. |
boolean |
remove(java.lang.Object object,
int nCopies)
Deprecated. Removes nCopies copies of the specified object from the Bag. |
boolean |
removeAll(java.util.Collection coll)
Deprecated. (Violation) Remove all elements represented in the given collection, respecting cardinality. |
boolean |
retainAll(Bag other)
Deprecated. Remove any members of the bag that are not in the given bag, respecting cardinality. |
boolean |
retainAll(java.util.Collection coll)
Deprecated. Remove any members of the bag that are not in the given bag, respecting cardinality. |
protected void |
setMap(java.util.Map map)
Deprecated. Utility method for implementations to set the map that backs this bag. |
int |
size()
Deprecated. Returns the number of elements in this bag. |
java.lang.Object[] |
toArray()
Deprecated. Returns an array of all of this bag's elements. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Deprecated. Returns an array of all of this bag's elements. |
java.lang.String |
toString()
Deprecated. Implement a toString() method suitable for debugging. |
java.util.Set |
uniqueSet()
Deprecated. Returns an unmodifiable view of the underlying map's key set. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultMapBag()
setMap(Map) in
their constructors.
protected DefaultMapBag(java.util.Map map)
map - the map to assign| Method Detail |
|---|
public boolean add(java.lang.Object object)
add in interface java.util.Collectionadd in interface Bagobject - the object to add
true if the object was not already in the uniqueSet
public boolean add(java.lang.Object object,
int nCopies)
add in interface Bagobject - the object to search fornCopies - the number of copies to add
true if the object was not already in the uniqueSetpublic boolean addAll(java.util.Collection coll)
add(Object) for each element in the given collection.
addAll in interface java.util.Collectioncoll - the collection to add
true if this call changed the bagpublic void clear()
clear in interface java.util.Collectionpublic boolean contains(java.lang.Object object)
contains in interface java.util.Collectionobject - the object to search for
public boolean containsAll(java.util.Collection coll)
containsAll in interface java.util.CollectioncontainsAll in interface Bagcoll - the collection to check against
true if the Bag contains all the collectionpublic boolean containsAll(Bag other)
true if the bag contains all elements in
the given collection, respecting cardinality.
other - the bag to check against
true if the Bag contains all the collectionpublic boolean equals(java.lang.Object object)
equals in interface java.util.Collectionequals in class java.lang.Objectobject - the object to test for equality
public int hashCode()
hashCode in interface java.util.CollectionhashCode in class java.lang.Objectpublic boolean isEmpty()
isEmpty in interface java.util.Collectionpublic java.util.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 java.lang.Iterableiterator in interface java.util.Collectioniterator in interface Bagpublic boolean remove(java.lang.Object object)
Bag
This will also remove the object from the Bag.uniqueSet().
According to the Collection.remove(Object) method,
this method should only remove the first occurrence of the
given object, not all occurrences.
remove in interface java.util.Collectionremove in interface Bagtrue if this call changed the collection
public boolean remove(java.lang.Object object,
int nCopies)
BagnCopies 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.
remove in interface Bagobject - the object to removenCopies - the number of copies to remove
true if this call changed the collectionpublic boolean removeAll(java.util.Collection coll)
Bagcoll 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.
removeAll in interface java.util.CollectionremoveAll in interface Bagcoll - the collection to remove
true if this call changed the collectionpublic boolean retainAll(java.util.Collection coll)
retainAll in interface java.util.CollectionretainAll in interface Bagcoll - the collection to retain
public boolean retainAll(Bag other)
other - the bag to retain
true if this call changed the collectionretainAll(Collection)public java.lang.Object[] toArray()
toArray in interface java.util.Collectionpublic java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.Collectionarray - the array to populate
public int getCount(java.lang.Object object)
getCount in interface Bagobject - the object to search for
public java.util.Set uniqueSet()
uniqueSet in interface Bagpublic int size()
size in interface java.util.Collectionsize in interface Bagprotected int calcTotalSize()
protected void setMap(java.util.Map map)
protected java.util.Map getMap()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||