|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjodd.util.collection.HashBag<E>
public class HashBag<E>
HashBag implementation of a Bag
| Field Summary | |
|---|---|
protected java.util.Map<E,MutableInteger> |
map
|
protected int |
size
|
| Constructor Summary | |
|---|---|
HashBag()
|
|
HashBag(java.util.Collection<? extends E> coll)
|
|
| Method Summary | ||
|---|---|---|
boolean |
add(E object)
Adds a new element to the bag, incrementing its count in the underlying map. |
|
boolean |
add(E object,
int nCopies)
Adds a new element to the bag, incrementing its count in the map. |
|
boolean |
addAll(java.util.Collection<? extends E> 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. |
|
boolean |
containsAll(java.util.Collection<?> coll)
Determines if the bag contains all the collection elements.. |
|
boolean |
equals(java.lang.Object object)
Compares bag to another. |
|
int |
getCount(java.lang.Object object)
Returns the number of occurrence of the given element in bag. |
|
int |
hashCode()
Gets a hash code for the Bag compatible with the definition of equals. |
|
boolean |
isEmpty()
Returns true if bag is empty. |
|
java.util.Iterator<E> |
iterator()
Returns 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 the bag. |
|
java.lang.Object[] |
toArray()
Returns an array of all of bag's elements. |
|
|
toArray(T[] array)
Populates an array with all of this bag's elements. |
|
java.lang.String |
toString()
Implement a toString() method suitable for debugging. |
|
java.util.Set<E> |
uniqueSet()
Returns a Set of unique elements in the Bag. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Map<E,MutableInteger> map
protected int size
| Constructor Detail |
|---|
public HashBag()
public HashBag(java.util.Collection<? extends E> coll)
| Method Detail |
|---|
public int size()
size in interface java.util.Collection<E>size in interface Bag<E>public boolean isEmpty()
true if bag is empty.
isEmpty in interface java.util.Collection<E>public int getCount(java.lang.Object object)
getCount in interface Bag<E>object - the object to search for
public boolean contains(java.lang.Object object)
contains in interface java.util.Collection<E>true if the bag contains the given elementpublic boolean containsAll(java.util.Collection<?> coll)
containsAll in interface java.util.Collection<E>containsAll in interface Bag<E>coll - the collection to check against
true if the Bag contains all the collection elementspublic java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in interface Bag<E>public boolean add(E object)
add in interface java.util.Collection<E>add in interface Bag<E>object - the object to add
true if the object was not already in the bag
public boolean add(E object,
int nCopies)
add in interface Bag<E>object - the object to addnCopies - the number of copies to add
true if the object was not already in the bagpublic boolean addAll(java.util.Collection<? extends E> coll)
add(Object) for each element in the given collection.
addAll in interface java.util.Collection<E>true if this call changed the bagpublic void clear()
clear in interface java.util.Collection<E>public boolean remove(java.lang.Object object)
remove in interface java.util.Collection<E>remove in interface Bag<E>true if the bag changed
public boolean remove(java.lang.Object object,
int nCopies)
remove in interface Bag<E>object - the object to removenCopies - the number of copies to remove
true if the bag changedpublic boolean removeAll(java.util.Collection<?> coll)
removeAll in interface java.util.Collection<E>removeAll in interface Bag<E>coll - the collection to remove
true if the bag changedpublic boolean retainAll(java.util.Collection<?> coll)
retainAll in interface java.util.Collection<E>retainAll in interface Bag<E>coll - the collection to retain
true if this call changed the collectionpublic java.util.Set<E> uniqueSet()
BagSet of unique elements in the Bag.
Uniqueness constraints are the same as those in Set.
uniqueSet in interface Bag<E>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>public <T> T[] toArray(T[] array)
toArray in interface java.util.Collection<E>public boolean equals(java.lang.Object object)
equals in interface java.util.Collection<E>equals in class java.lang.Objecttrue if equalpublic int hashCode()
(e==null ? 0 : e.hashCode()) ^ noOccurances).
This hash code is compatible with the Set interface.
hashCode in interface java.util.Collection<E>hashCode 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 | ||||||||