|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.commons.collections.DefaultMapBag
This class provides 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 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.
| Nested Class Summary | |
private class |
DefaultMapBag.BagIterator |
| Field Summary | |
private java.util.Map |
_map |
private int |
_mods |
private int |
_total |
| Constructor Summary | |
DefaultMapBag()Constructor. |
|
| Method Summary | |
boolean |
add(java.lang.Object o)Adds a new element to the bag by incrementing its count in the underlying map. |
boolean |
add(java.lang.Object o, int i)Adds a new element to the bag by incrementing its count in the map. |
boolean |
addAll(java.util.Collection c)Invokes add(Object) for each element in the given collection. |
protected int |
calcTotalSize()Actually walks the bag to make sure the count is correct and resets the running total |
void |
clear()Clears the bag by clearing the underlying map. |
boolean |
contains(java.lang.Object o)Determines if the bag contains the given element by checking if the underlying map contains the element as a key. |
boolean |
containsAll(Bag other)Returns true if the bag contains all elements in the given collection, respecting cardinality. |
boolean |
containsAll(java.util.Collection c)(Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality. |
boolean |
equals(java.lang.Object o)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. |
private java.util.List |
extractList()Create a list for use in iteration, etc. |
int |
getCount(java.lang.Object o)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()Returns the hash code of the underlying map. |
boolean |
isEmpty()Returns true if the underlying map is empty. |
java.util.Iterator |
iterator()Returns an DefaultMapBag.BagIterator over the entire set of members, including copies due to cardinality. |
private int |
modCount()Return number of modifications for iterator |
boolean |
remove(java.lang.Object o)(Violation) Remove all occurrences of the given object from the bag, and do not represent the object in the uniqueSet(). |
boolean |
remove(java.lang.Object o, int i)Remove the given number of occurrences from the bag. |
boolean |
removeAll(java.util.Collection c)(Violation) Remove all elements represented in the given collection, respecting cardinality. |
boolean |
retainAll(Bag other)Remove any members of the bag that are not in the given bag, respecting cardinality. |
boolean |
retainAll(java.util.Collection c)Remove any members of the bag that are not in the given bag, respecting cardinality. |
protected void |
setMap(java.util.Map m)Utility method for implementations to set the map that backs this bag. |
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[] a)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 |
| Field Detail |
private java.util.Map _map
private int _total
private int _mods
| Constructor Detail |
public DefaultMapBag()
setMap(Map) in their constructors.
| Method Detail |
public boolean add(java.lang.Object o)
add in interface Bagtrue if the object was not already in the uniqueSetBag.add(Object)
public boolean add(java.lang.Object o,
int i)
add in interface Bagtrue if the object was not already in the uniqueSetBag.add(Object, int)public boolean addAll(java.util.Collection c)
add(Object) for each element in the given collection.
addAll in interface java.util.CollectionCollection.addAll(Collection)public void clear()
clear in interface java.util.Collectionpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectionpublic boolean containsAll(java.util.Collection c)
Bagtrue if the bag contains all elements in the given collection, respecting cardinality. That is, if the given collection C contains n copies of a given object, calling Bag.getCount(Object) on that object must be >= n for all n in C.
The Collection.containsAll(Collection) method specifies that cardinality should not be respected; this method should return true if the bag contains at least one of every object contained in the given collection. A future version of this method will comply with that contract.
containsAll in interface Bagpublic boolean containsAll(Bag other)
true if the bag contains all elements in the given collection, respecting cardinality.
containsAll(Collection)public boolean equals(java.lang.Object o)
equals in interface java.util.Collectiono - the object to test for equalitypublic int hashCode()
hashCode in interface java.util.Collectionpublic boolean isEmpty()
isEmpty in interface java.util.Collectionpublic java.util.Iterator iterator()
BagIterator over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.
iterator in interface Bagpublic boolean remove(java.lang.Object o)
BagBag.uniqueSet().
According to the Collection.remove(Object) method, this method should only remove the first occurrence of the given object, not all occurrences. A future version of this method will comply with the contract by only removing one occurrence of the given object.
remove in interface Bagtrue if this call changed the collectionBag.remove(Object, int)
public boolean remove(java.lang.Object o,
int i)
Bagi occurrences or less, the item will be removed from the Bag.uniqueSet().
remove in interface Bagtrue if this call changed the collectionBag.getCount(Object), Bag.remove(Object)public boolean removeAll(java.util.Collection c)
BagC 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 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. A future version of this method will comply with that contract.
removeAll in interface Bagtrue if this call changed the collectionpublic boolean retainAll(java.util.Collection c)
retainAll in interface Bagpublic boolean retainAll(Bag other)
true if this call changed the collectionretainAll(Collection)public java.lang.Object[] toArray()
toArray in interface java.util.Collectionpublic java.lang.Object[] toArray(java.lang.Object[] a)
toArray in interface java.util.Collectiona - the array to populatepublic int getCount(java.lang.Object o)
getCount in interface BagBag.getCount(Object)public java.util.Set uniqueSet()
uniqueSet in interface Bagpublic int size()
size in interface Bagprotected int calcTotalSize()
protected void setMap(java.util.Map m)
protected java.util.Map getMap()
private java.util.List extractList()
private int modCount()
public java.lang.String toString()
|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||