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
@Deprecated(since="2021-04-30") 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 theBag
interface 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 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.Invokesadd(Object)
for each element in the given collection.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(java.util.Collection coll)
Deprecated.Determines if the bag contains the given elements.boolean
containsAll(Bag other)
Deprecated.Returnstrue
if the bag contains all elements in the given collection, respecting cardinality.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.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 anIterator
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.RemovesnCopies
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(java.util.Collection coll)
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.boolean
retainAll(Bag other)
Deprecated.Remove any members of the bag that are not in the given bag, respecting cardinality.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.
-
-
-
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:
addAll
in interfacejava.util.Collection
- Parameters:
coll
- the collection to add- Returns:
true
if this call changed the bag
-
clear
public void clear()
Deprecated.Clears the bag by clearing the underlying map.- Specified by:
clear
in 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:
contains
in 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:
containsAll
in interfaceBag
- Specified by:
containsAll
in interfacejava.util.Collection
- Parameters:
coll
- the collection to check against- Returns:
true
if the Bag contains all the collection
-
containsAll
public boolean containsAll(Bag other)
Deprecated.Returnstrue
if the bag contains all elements in the given collection, respecting cardinality.- Parameters:
other
- the bag to check against- Returns:
true
if 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:
equals
in interfacejava.util.Collection
- Overrides:
equals
in 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:
hashCode
in interfacejava.util.Collection
- Overrides:
hashCode
in 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:
isEmpty
in interfacejava.util.Collection
- Returns:
- true if there are no elements in this bag
-
iterator
public java.util.Iterator iterator()
Deprecated.Description copied from interface:Bag
Returns anIterator
over 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:Bag
RemovesnCopies
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.
-
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 collectioncoll
containsn
copies of a given object, the bag will haven
fewer copies, assuming the bag had at leastn
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.
-
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:
true
if 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:
toArray
in 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:
toArray
in 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:
toString
in classjava.lang.Object
- Returns:
- a debugging toString
-
-