java.lang.Object | |
↳ | org.apache.commons.collections.DefaultMapBag |
Known Direct Subclasses |
This class is 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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
No-argument constructor.
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that assigns the specified Map as the backing store.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a new element to the bag by incrementing its count in the map.
| |||||||||||
Adds a new element to the bag by incrementing its count in the
underlying map.
| |||||||||||
Invokes
add(Object) for each element in the given collection. | |||||||||||
Clears the bag by clearing the underlying map.
| |||||||||||
Determines if the bag contains the given element by checking if the
underlying map contains the element as a key.
| |||||||||||
Determines if the bag contains the given elements.
| |||||||||||
Returns
true if the bag contains all elements in
the given collection, respecting cardinality. | |||||||||||
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.
| |||||||||||
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
| |||||||||||
Returns the hash code of the underlying map.
| |||||||||||
Returns true if the underlying map is empty.
| |||||||||||
Returns an
Iterator over the entire set of members,
including copies due to cardinality. | |||||||||||
Removes
nCopies copies of the specified object from the Bag. | |||||||||||
(Violation)
Removes all occurrences of the given object from the bag.
| |||||||||||
(Violation)
Remove all elements represented in the given collection,
respecting cardinality.
| |||||||||||
Remove any members of the bag that are not in the given
bag, respecting cardinality.
| |||||||||||
Remove any members of the bag that are not in the given
bag, respecting cardinality.
| |||||||||||
Returns the number of elements in this bag.
| |||||||||||
Returns an array of all of this bag's elements.
| |||||||||||
Returns an array of all of this bag's elements.
| |||||||||||
Implement a toString() method suitable for debugging.
| |||||||||||
Returns an unmodifiable view of the underlying map's key set.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Actually walks the bag to make sure the count is correct and
resets the running total
| |||||||||||
Utility method for implementations to access the map that backs
this bag.
| |||||||||||
Utility method for implementations to set the map that backs
this bag.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Iterable
| |||||||||||
From interface
java.util.Collection
| |||||||||||
From interface
org.apache.commons.collections.Bag
|
No-argument constructor.
Subclasses should invoke setMap(Map)
in
their constructors.
Constructor that assigns the specified Map as the backing store. The map must be empty.
map | the map to assign |
---|
Adds a new element to the bag by incrementing its count in the map.
object | the object to search for |
---|---|
nCopies | the number of copies to add |
true
if the object was not already in the uniqueSet
Adds a new element to the bag by incrementing its count in the underlying map.
object | the object to add |
---|
true
if the object was not already in the uniqueSet
Invokes add(Object)
for each element in the given collection.
coll | the collection to add |
---|
true
if this call changed the bag
Clears the bag by clearing the underlying map.
Determines if the bag contains the given element by checking if the underlying map contains the element as a key.
object | the object to search for |
---|
Determines if the bag contains the given elements.
coll | the collection to check against |
---|
true
if the Bag contains all the collection
Returns 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 collection
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.
object | the object to test for equality |
---|
Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map.
object | the object to search for |
---|
Returns the hash code of the underlying map.
Returns true if the underlying map is empty.
Returns an Iterator
over the entire set of members,
including copies due to cardinality. This iterator is fail-fast
and will not tolerate concurrent modifications.
Removes 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.
object | the object to remove |
---|---|
nCopies | the number of copies to remove |
true
if this call changed the collection
(Violation) Removes all occurrences of the given object from the bag.
This will also remove the object from the uniqueSet()
.
According to the remove(Object)
method,
this method should only remove the first occurrence of the
given object, not all occurrences.
true
if this call changed the collection
(Violation)
Remove all elements represented in the given collection,
respecting cardinality. That is, if the given collection
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 removeAll(Collection)
method specifies
that cardinality should not be respected; this method should
remove all occurrences of every object contained in the
given collection.
coll | the collection to remove |
---|
true
if this call changed the collection
Remove any members of the bag that are not in the given bag, respecting cardinality.
coll | the collection to retain |
---|
Remove any members of the bag that are not in the given bag, respecting cardinality.
other | the bag to retain |
---|
true
if this call changed the collection
Returns the number of elements in this bag.
Returns an array of all of this bag's elements.
array | the array to populate |
---|
Returns an array of all of this bag's elements.
Implement a toString() method suitable for debugging.
Returns an unmodifiable view of the underlying map's key set.
Actually walks the bag to make sure the count is correct and resets the running total
Utility method for implementations to access the map that backs this bag. Not intended for interactive use outside of subclasses.
Utility method for implementations to set the map that backs this bag. Not intended for interactive use outside of subclasses.