|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections.bag.AbstractMapBag
public abstract class AbstractMapBag
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 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(java.util.Map map)
Constructor that assigns the specified Map as the backing store. |
| Method Summary | |
|---|---|
boolean |
add(java.lang.Object object)
Adds a new element to the bag, incrementing its count in the underlying map. |
boolean |
add(java.lang.Object object,
int nCopies)
Adds a new element to the bag, incrementing its count in the map. |
boolean |
addAll(java.util.Collection coll)
Invokes add(Object) for each element in the given collection. |
void |
clear()
Clears the bag by clearing the underlying map. |
boolean |
contains(java.lang.Object object)
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)
Determines if the bag contains the given elements. |
protected void |
doReadObject(java.util.Map map,
java.io.ObjectInputStream in)
Read the map in using a custom routine. |
protected void |
doWriteObject(java.io.ObjectOutputStream out)
Write the map out using a custom routine. |
boolean |
equals(java.lang.Object object)
Compares this Bag to another. |
int |
getCount(java.lang.Object object)
Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. |
protected java.util.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. |
java.util.Iterator |
iterator()
Gets an iterator over the bag elements. |
boolean |
remove(java.lang.Object object)
Removes all copies of the specified object from the bag. |
boolean |
remove(java.lang.Object object,
int nCopies)
Removes a specified number of copies of an object from the bag. |
boolean |
removeAll(java.util.Collection coll)
Removes objects from the bag according to their count in the specified collection. |
boolean |
retainAll(java.util.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. |
java.lang.Object[] |
toArray()
Returns an array of all of this bag's elements. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Returns an array of all of this bag's elements. |
java.lang.String |
toString()
Implement a toString() method suitable for debugging. |
java.util.Set |
uniqueSet()
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, wait |
| Constructor Detail |
|---|
protected AbstractMapBag()
protected AbstractMapBag(java.util.Map map)
map - the map to assign| Method Detail |
|---|
protected java.util.Map getMap()
public int size()
size in interface java.util.Collectionsize in interface Bagpublic boolean isEmpty()
isEmpty in interface java.util.Collectionpublic int getCount(java.lang.Object object)
getCount in interface Bagobject - the object to search for
public boolean contains(java.lang.Object object)
contains in interface java.util.Collectionobject - the object to search for
public boolean containsAll(java.util.Collection coll)
containsAll in interface java.util.CollectioncontainsAll in interface Bagcoll - the collection to check against
true if the Bag contains all the collectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface Bagpublic boolean add(java.lang.Object object)
add in interface java.util.Collectionadd in interface Bagobject - the object to add
true if the object was not already in the uniqueSet
public boolean add(java.lang.Object object,
int nCopies)
add in interface Bagobject - the object to search fornCopies - the number of copies to add
true if the object was not already in the uniqueSetpublic boolean addAll(java.util.Collection coll)
add(Object) for each element in the given collection.
addAll in interface java.util.Collectioncoll - the collection to add
true if this call changed the bagpublic void clear()
clear in interface java.util.Collectionpublic boolean remove(java.lang.Object object)
remove in interface java.util.Collectionremove in interface Bagobject - the object to remove
public boolean remove(java.lang.Object object,
int nCopies)
remove in interface Bagobject - the object to removenCopies - the number of copies to remove
public boolean removeAll(java.util.Collection coll)
removeAll in interface java.util.CollectionremoveAll in interface Bagcoll - the collection to use
public boolean retainAll(java.util.Collection coll)
retainAll in interface java.util.CollectionretainAll in interface Bagcoll - the collection to retain
public java.lang.Object[] toArray()
toArray in interface java.util.Collectionpublic java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.Collectionarray - the array to populate
public java.util.Set uniqueSet()
uniqueSet in interface Bag
protected void doWriteObject(java.io.ObjectOutputStream out)
throws java.io.IOException
out - the output stream
java.io.IOException
protected void doReadObject(java.util.Map map,
java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
map - the map to usein - the input stream
java.io.IOException
java.lang.ClassNotFoundExceptionpublic boolean equals(java.lang.Object object)
equals in interface java.util.Collectionequals in class java.lang.Objectobject - the Bag to compare to
public int hashCode()
(e==null ? 0 : e.hashCode()) ^ noOccurances).
This hash code is compatible with the Set interface.
hashCode in interface java.util.CollectionhashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||