java.lang.Object | |
↳ | org.apache.commons.collections.bag.AbstractMapBag |
Known Direct Subclasses |
Abstract implementation of the Bag
interface to simplify the creation
of subclass implementations.
Subclasses specify a Map implementation to use as the internal storage. 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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractMapBag.MutableInteger | Mutable integer class for storing the data. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor needed for subclass serialisation.
| |||||||||||
Constructor that assigns the specified Map as the backing store.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a new element to the bag, incrementing its count in the map.
| |||||||||||
Adds a new element to the bag, 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.
| |||||||||||
Compares this Bag to another.
| |||||||||||
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
| |||||||||||
Gets a hash code for the Bag compatible with the definition of equals.
| |||||||||||
Returns true if the underlying map is empty.
| |||||||||||
Gets an iterator over the bag elements.
| |||||||||||
Removes a specified number of copies of an object from the bag.
| |||||||||||
Removes all copies of the specified object from the bag.
| |||||||||||
Removes objects from the bag according to their count in the specified collection.
| |||||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Read the map in using a custom routine.
| |||||||||||
Write the map out using a custom routine.
| |||||||||||
Utility method for implementations to access 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
|
Constructor needed for subclass serialisation.
Constructor that assigns the specified Map as the backing store. The map must be empty and non-null.
map | the map to assign |
---|
Adds a new element to the bag, 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, 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
Compares this Bag to another. This Bag equals another Bag if it contains the same number of occurrences of the same elements.
object | the Bag to compare to |
---|
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 |
---|
Gets a hash code for the Bag compatible with the definition of equals.
The hash code is defined as the sum total of a hash code for each element.
The per element hash code is defined as
(e==null ? 0 : e.hashCode()) ^ noOccurances)
.
This hash code is compatible with the Set interface.
Returns true if the underlying map is empty.
Gets an iterator over the bag elements. Elements present in the Bag more than once will be returned repeatedly.
Removes a specified number of copies of an object from the bag.
object | the object to remove |
---|---|
nCopies | the number of copies to remove |
Removes all copies of the specified object from the bag.
object | the object to remove |
---|
Removes objects from the bag according to their count in the specified collection.
coll | the collection to use |
---|
Remove any members of the bag that are not in the given bag, respecting cardinality.
coll | the collection to retain |
---|
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.
array | the array to populate |
---|
Implement a toString() method suitable for debugging.
Returns an unmodifiable view of the underlying map's key set.
Read the map in using a custom routine.
map | the map to use |
---|---|
in | the input stream |
IOException | |
ClassNotFoundException | |
IOException |
Utility method for implementations to access the map that backs this bag. Not intended for interactive use outside of subclasses.