Package org.apache.commons.collections
Class DefaultMapBag
- java.lang.Object
 - 
- org.apache.commons.collections.DefaultMapBag
 
 
- 
- All Implemented Interfaces:
 java.lang.Iterable,java.util.Collection,Bag
public abstract class DefaultMapBag extends java.lang.Object implements Bag
Deprecated.Moved to bag subpackage as AbstractMapBag. Due to be removed in v4.0.A skeletal implementation of theBaginterface to minimize the effort required for target implementations. Subclasses need only to callsetMap(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.
- Since:
 - Commons Collections 2.0
 
 
- 
- 
Constructor Summary
Constructors Constructor Description DefaultMapBag()Deprecated.No-argument constructor. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadd(java.lang.Object object)Deprecated.Adds a new element to the bag by incrementing its count in the underlying map.booleanadd(java.lang.Object object, int nCopies)Deprecated.Adds a new element to the bag by incrementing its count in the map.booleanaddAll(java.util.Collection coll)Deprecated.Invokesadd(Object)for each element in the given collection.voidclear()Deprecated.Clears the bag by clearing the underlying map.booleancontains(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.booleancontainsAll(java.util.Collection coll)Deprecated.Determines if the bag contains the given elements.booleancontainsAll(Bag other)Deprecated.Returnstrueif the bag contains all elements in the given collection, respecting cardinality.booleanequals(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.intgetCount(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.inthashCode()Deprecated.Returns the hash code of the underlying map.booleanisEmpty()Deprecated.Returns true if the underlying map is empty.java.util.Iteratoriterator()Deprecated.Returns anIteratorover the entire set of members, including copies due to cardinality.booleanremove(java.lang.Object object)Deprecated.(Violation) Removes all occurrences of the given object from the bag.booleanremove(java.lang.Object object, int nCopies)Deprecated.RemovesnCopiescopies of the specified object from the Bag.booleanremoveAll(java.util.Collection coll)Deprecated.(Violation) Remove all elements represented in the given collection, respecting cardinality.booleanretainAll(java.util.Collection coll)Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.booleanretainAll(Bag other)Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.intsize()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.StringtoString()Deprecated.Implement a toString() method suitable for debugging.java.util.SetuniqueSet()Deprecated.Returns an unmodifiable view of the underlying map's key set. 
 - 
 
- 
- 
Method Detail
- 
add
public boolean add(java.lang.Object object)
Deprecated.Adds a new element to the bag by incrementing its count in the underlying map. 
- 
add
public boolean add(java.lang.Object object, int nCopies)Deprecated.Adds a new element to the bag by incrementing its count in the map. 
- 
addAll
public boolean addAll(java.util.Collection coll)
Deprecated.Invokesadd(Object)for each element in the given collection.- Specified by:
 addAllin interfacejava.util.Collection- Parameters:
 coll- the collection to add- Returns:
 trueif this call changed the bag
 
- 
clear
public void clear()
Deprecated.Clears the bag by clearing the underlying map.- Specified by:
 clearin interfacejava.util.Collection
 
- 
contains
public 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.- Specified by:
 containsin interfacejava.util.Collection- Parameters:
 object- the object to search for- Returns:
 - true if the bag contains the given element
 
 
- 
containsAll
public boolean containsAll(java.util.Collection coll)
Deprecated.Determines if the bag contains the given elements.- Specified by:
 containsAllin interfaceBag- Specified by:
 containsAllin interfacejava.util.Collection- Parameters:
 coll- the collection to check against- Returns:
 trueif the Bag contains all the collection
 
- 
containsAll
public boolean containsAll(Bag other)
Deprecated.Returnstrueif the bag contains all elements in the given collection, respecting cardinality.- Parameters:
 other- the bag to check against- Returns:
 trueif the Bag contains all the collection
 
- 
equals
public 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.- Specified by:
 equalsin interfacejava.util.Collection- Overrides:
 equalsin classjava.lang.Object- Parameters:
 object- the object to test for equality- Returns:
 - true if that object equals this bag
 
 
- 
hashCode
public int hashCode()
Deprecated.Returns the hash code of the underlying map.- Specified by:
 hashCodein interfacejava.util.Collection- Overrides:
 hashCodein classjava.lang.Object- Returns:
 - the hash code of the underlying map
 
 
- 
isEmpty
public boolean isEmpty()
Deprecated.Returns true if the underlying map is empty.- Specified by:
 isEmptyin interfacejava.util.Collection- Returns:
 - true if there are no elements in this bag
 
 
- 
iterator
public java.util.Iterator iterator()
Deprecated.Description copied from interface:BagReturns anIteratorover the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications. 
- 
remove
public boolean remove(java.lang.Object object)
Deprecated.Description copied from interface:Bag(Violation) Removes all occurrences of the given object from the 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
public boolean remove(java.lang.Object object, int nCopies)Deprecated.Description copied from interface:BagRemovesnCopiescopies 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.
 
- 
removeAll
public boolean removeAll(java.util.Collection coll)
Deprecated.Description copied from interface:Bag(Violation) Remove all elements represented in the given collection, respecting cardinality. That is, if the given collectioncollcontainsncopies of a given object, the bag will havenfewer copies, assuming the bag had at leastncopies 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. 
- 
retainAll
public boolean retainAll(java.util.Collection coll)
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality. 
- 
retainAll
public boolean retainAll(Bag other)
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.- Parameters:
 other- the bag to retain- Returns:
 trueif this call changed the collection- See Also:
 retainAll(Collection)
 
- 
toArray
public java.lang.Object[] toArray()
Deprecated.Returns an array of all of this bag's elements.- Specified by:
 toArrayin interfacejava.util.Collection- Returns:
 - an array of all of this bag's elements
 
 
- 
toArray
public java.lang.Object[] toArray(java.lang.Object[] array)
Deprecated.Returns an array of all of this bag's elements.- Specified by:
 toArrayin interfacejava.util.Collection- Parameters:
 array- the array to populate- Returns:
 - an array of all of this bag's elements
 
 
- 
getCount
public 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. 
- 
uniqueSet
public java.util.Set uniqueSet()
Deprecated.Returns an unmodifiable view of the underlying map's key set. 
- 
size
public int size()
Deprecated.Returns the number of elements in this bag. 
- 
toString
public java.lang.String toString()
Deprecated.Implement a toString() method suitable for debugging.- Overrides:
 toStringin classjava.lang.Object- Returns:
 - a debugging toString
 
 
 - 
 
 -