Package org.apache.commons.collections
Class DefaultMapBag
java.lang.Object
org.apache.commons.collections.DefaultMapBag
- All Implemented Interfaces:
Iterable,Collection,Bag
Deprecated.
Moved to bag subpackage as AbstractMapBag. Due to be removed in v4.0.
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.
- Since:
- Commons Collections 2.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- Chuck Burdick, Michael A. Smith, Stephen Colebourne, Janek Bogucki
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.No-argument constructor.protectedDefaultMapBag(Map map) Deprecated.Constructor that assigns the specified Map as the backing store. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.Adds a new element to the bag by incrementing its count in the underlying map.booleanDeprecated.Adds a new element to the bag by incrementing its count in the map.booleanaddAll(Collection coll) Deprecated.Invokesadd(Object)for each element in the given collection.protected intDeprecated.Actually walks the bag to make sure the count is correct and resets the running totalvoidclear()Deprecated.Clears the bag by clearing the underlying map.booleanDeprecated.Determines if the bag contains the given element by checking if the underlying map contains the element as a key.booleancontainsAll(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.booleanDeprecated.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.intDeprecated.Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map.protected MapgetMap()Deprecated.Utility method for implementations to access the map that backs this bag.inthashCode()Deprecated.Returns the hash code of the underlying map.booleanisEmpty()Deprecated.Returns true if the underlying map is empty.iterator()Deprecated.Returns anIteratorover the entire set of members, including copies due to cardinality.booleanDeprecated.(Violation) Removes all occurrences of the given object from the bag.booleanDeprecated.RemovesnCopiescopies of the specified object from the Bag.booleanremoveAll(Collection coll) Deprecated.(Violation) Remove all elements represented in the given collection, respecting cardinality.booleanretainAll(Collection coll) Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.booleanDeprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.protected voidDeprecated.Utility method for implementations to set the map that backs this bag.intsize()Deprecated.Returns the number of elements in this bag.Object[]toArray()Deprecated.Returns an array of all of this bag's elements.Object[]Deprecated.Returns an array of all of this bag's elements.toString()Deprecated.Implement a toString() method suitable for debugging.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, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
DefaultMapBag
public DefaultMapBag()Deprecated.No-argument constructor. Subclasses should invokesetMap(Map)in their constructors. -
DefaultMapBag
Deprecated.Constructor that assigns the specified Map as the backing store. The map must be empty.- Parameters:
map- the map to assign
-
-
Method Details
-
add
Deprecated.Adds a new element to the bag by incrementing its count in the underlying map.- Specified by:
addin interfaceBag- Specified by:
addin interfaceCollection- Parameters:
object- the object to add- Returns:
trueif the object was not already in theuniqueSet
-
add
Deprecated.Adds a new element to the bag by incrementing its count in the map. -
addAll
Deprecated.Invokesadd(Object)for each element in the given collection.- Specified by:
addAllin interfaceCollection- 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 interfaceCollection
-
contains
Deprecated.Determines if the bag contains the given element by checking if the underlying map contains the element as a key.- Specified by:
containsin interfaceCollection- Parameters:
object- the object to search for- Returns:
- true if the bag contains the given element
-
containsAll
Deprecated.Determines if the bag contains the given elements.- Specified by:
containsAllin interfaceBag- Specified by:
containsAllin interfaceCollection- Parameters:
coll- the collection to check against- Returns:
trueif the Bag contains all the collection
-
containsAll
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
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 interfaceCollection- Overrides:
equalsin classObject- 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 interfaceCollection- Overrides:
hashCodein classObject- Returns:
- the hash code of the underlying map
-
isEmpty
public boolean isEmpty()Deprecated.Returns true if the underlying map is empty.- Specified by:
isEmptyin interfaceCollection- Returns:
- true if there are no elements in this bag
-
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
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.- Specified by:
removein interfaceBag- Specified by:
removein interfaceCollection- Returns:
trueif this call changed the collection
-
remove
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
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.- Specified by:
removeAllin interfaceBag- Specified by:
removeAllin interfaceCollection- Parameters:
coll- the collection to remove- Returns:
trueif this call changed the collection
-
retainAll
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.- Specified by:
retainAllin interfaceBag- Specified by:
retainAllin interfaceCollection- Parameters:
coll- the collection to retain- Returns:
- true if this call changed the collection
-
retainAll
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:
-
toArray
Deprecated.Returns an array of all of this bag's elements.- Specified by:
toArrayin interfaceCollection- Returns:
- an array of all of this bag's elements
-
toArray
Deprecated.Returns an array of all of this bag's elements.- Specified by:
toArrayin interfaceCollection- Parameters:
array- the array to populate- Returns:
- an array of all of this bag's elements
-
getCount
Deprecated.Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. -
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.- Specified by:
sizein interfaceBag- Specified by:
sizein interfaceCollection- Returns:
- the number of elements in this bag
-
calcTotalSize
protected int calcTotalSize()Deprecated.Actually walks the bag to make sure the count is correct and resets the running total- Returns:
- the current total size
-
setMap
Deprecated.Utility method for implementations to set the map that backs this bag. Not intended for interactive use outside of subclasses. -
getMap
Deprecated.Utility method for implementations to access the map that backs this bag. Not intended for interactive use outside of subclasses. -
toString
Deprecated.Implement a toString() method suitable for debugging.
-