org.apache.commons.collections.bag
public abstract class AbstractMapBag extends Object implements Bag
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.
Since: Commons Collections 3.0 (previously DefaultMapBag v2.0)
Version: $Revision: 219131 $ $Date: 2005-07-15 00:11:12 +0100 (Fri, 15 Jul 2005) $
Nested Class Summary | |
---|---|
protected static class | AbstractMapBag.MutableInteger
Mutable integer class for storing the data. |
Constructor Summary | |
---|---|
protected | AbstractMapBag()
Constructor needed for subclass serialisation.
|
protected | AbstractMapBag(Map map)
Constructor that assigns the specified Map as the backing store.
|
Method Summary | |
---|---|
boolean | add(Object object)
Adds a new element to the bag, incrementing its count in the underlying map.
|
boolean | add(Object object, int nCopies)
Adds a new element to the bag, incrementing its count in the map.
|
boolean | addAll(Collection coll)
Invokes add for each element in the given collection.
|
void | clear()
Clears the bag by clearing the underlying map. |
boolean | contains(Object object)
Determines if the bag contains the given element by checking if the
underlying map contains the element as a key.
|
boolean | containsAll(Collection coll)
Determines if the bag contains the given elements.
|
protected void | doReadObject(Map map, ObjectInputStream in)
Read the map in using a custom routine. |
protected void | doWriteObject(ObjectOutputStream out)
Write the map out using a custom routine. |
boolean | equals(Object object)
Compares this Bag to another.
|
int | getCount(Object object)
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
|
protected Map | getMap()
Utility method for implementations to access the map that backs
this bag. |
int | hashCode()
Gets a hash code for the Bag compatible with the definition of equals.
|
boolean | isEmpty()
Returns true if the underlying map is empty.
|
Iterator | iterator()
Gets an iterator over the bag elements.
|
boolean | remove(Object object)
Removes all copies of the specified object from the bag.
|
boolean | remove(Object object, int nCopies)
Removes a specified number of copies of an object from the bag.
|
boolean | removeAll(Collection coll)
Removes objects from the bag according to their count in the specified collection.
|
boolean | retainAll(Collection coll)
Remove any members of the bag that are not in the given
bag, respecting cardinality.
|
int | size()
Returns the number of elements in this bag.
|
Object[] | toArray()
Returns an array of all of this bag's elements.
|
Object[] | toArray(Object[] array)
Returns an array of all of this bag's elements.
|
String | toString()
Implement a toString() method suitable for debugging.
|
Set | uniqueSet()
Returns an unmodifiable view of the underlying map's key set.
|
Parameters: map the map to assign
Parameters: object the object to add
Returns: true
if the object was not already in the uniqueSet
Parameters: object the object to search for nCopies the number of copies to add
Returns: true
if the object was not already in the uniqueSet
Parameters: coll the collection to add
Returns: true
if this call changed the bag
Parameters: object the object to search for
Returns: true if the bag contains the given element
Parameters: coll the collection to check against
Returns: true
if the Bag contains all the collection
Parameters: map the map to use in the input stream
Throws: IOException ClassNotFoundException
Parameters: out the output stream
Throws: IOException
Parameters: object the Bag to compare to
Returns: true if equal
Parameters: object the object to search for
Returns: the number of occurrences of the object, zero if not found
Returns: the map being used by the Bag
(e==null ? 0 : e.hashCode()) ^ noOccurances)
.
This hash code is compatible with the Set interface.
Returns: the hash code of the Bag
Returns: true if bag is empty
Returns: the iterator
Parameters: object the object to remove
Returns: true if the bag changed
Parameters: object the object to remove nCopies the number of copies to remove
Returns: true if the bag changed
Parameters: coll the collection to use
Returns: true if the bag changed
Parameters: coll the collection to retain
Returns: true if this call changed the collection
Returns: current size of the bag
Returns: an array of all of this bag's elements
Parameters: array the array to populate
Returns: an array of all of this bag's elements
Returns: a debugging toString
Returns: the set of unique elements in this bag