|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 assignMethod Detail |
---|
public boolean add(java.lang.Object object)
add
in interface java.util.Collection
add
in interface Bag
object
- 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 Bag
object
- the object to search fornCopies
- the number of copies to add
true
if the object was not already in the uniqueSet
public boolean addAll(java.util.Collection coll)
add(Object)
for each element in the given collection.
addAll
in interface java.util.Collection
coll
- the collection to add
true
if this call changed the bagpublic void clear()
clear
in interface java.util.Collection
public boolean contains(java.lang.Object object)
contains
in interface java.util.Collection
object
- the object to search for
public boolean containsAll(java.util.Collection coll)
containsAll
in interface java.util.Collection
containsAll
in interface Bag
coll
- 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.Collection
equals
in class java.lang.Object
object
- the object to test for equality
public int hashCode()
hashCode
in interface java.util.Collection
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public java.util.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 java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface Bag
public 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.Collection
remove
in interface Bag
true
if this call changed the collectionpublic boolean remove(java.lang.Object object, int nCopies)
Bag
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.
remove
in interface Bag
object
- the object to removenCopies
- the number of copies to remove
true
if this call changed the collectionpublic boolean removeAll(java.util.Collection coll)
Bag
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.
removeAll
in interface java.util.Collection
removeAll
in interface Bag
coll
- the collection to remove
true
if this call changed the collectionpublic boolean retainAll(java.util.Collection coll)
retainAll
in interface java.util.Collection
retainAll
in interface Bag
coll
- 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.Collection
public java.lang.Object[] toArray(java.lang.Object[] array)
toArray
in interface java.util.Collection
array
- the array to populate
public int getCount(java.lang.Object object)
getCount
in interface Bag
object
- the object to search for
public java.util.Set uniqueSet()
uniqueSet
in interface Bag
public int size()
size
in interface java.util.Collection
size
in interface Bag
protected 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 |