|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.bag.AbstractMapBag<E>
public abstract class AbstractMapBag<E>
Abstract implementation of the Bag
interface to simplify the creation
of subclass implementations.
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<E,AbstractMapBag.MutableInteger> map)
Constructor that assigns the specified Map as the backing store. |
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(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(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<E,AbstractMapBag.MutableInteger> 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(E object)
Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. |
protected Map<E,AbstractMapBag.MutableInteger> |
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<E> |
iterator()
Gets an iterator over the bag elements. |
boolean |
remove(E object,
int nCopies)
Removes a specified number of copies of an object from the bag. |
boolean |
remove(Object object)
Removes all copies of the specified 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<E> |
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(Map<E,AbstractMapBag.MutableInteger> map)
map
- the map to assignMethod Detail |
---|
protected Map<E,AbstractMapBag.MutableInteger> getMap()
public int size()
size
in interface Collection<E>
size
in interface Bag<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
public int getCount(E object)
getCount
in interface Bag<E>
object
- the object to search for
public boolean contains(Object object)
contains
in interface Collection<E>
object
- the object to search for
public boolean containsAll(Collection<?> coll)
containsAll
in interface Collection<E>
containsAll
in interface Bag<E>
coll
- the collection to check against
true
if the Bag contains all the collectionpublic Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Bag<E>
public boolean add(E object)
add
in interface Collection<E>
add
in interface Bag<E>
object
- the object to add
true
if the object was not already in the uniqueSet
public boolean add(E object, int nCopies)
add
in interface Bag<E>
object
- the object to search fornCopies
- the number of copies to add
true
if the object was not already in the uniqueSet
public boolean addAll(Collection<? extends E> coll)
add(Object)
for each element in the given collection.
addAll
in interface Collection<E>
coll
- the collection to add
true
if this call changed the bagpublic void clear()
clear
in interface Collection<E>
public boolean remove(Object object)
remove
in interface Collection<E>
remove
in interface Bag<E>
object
- the object to remove
public boolean remove(E object, int nCopies)
remove
in interface Bag<E>
object
- the object to removenCopies
- the number of copies to remove
public boolean removeAll(Collection<?> coll)
removeAll
in interface Collection<E>
removeAll
in interface Bag<E>
coll
- the collection to use
public boolean retainAll(Collection<?> coll)
retainAll
in interface Collection<E>
retainAll
in interface Bag<E>
coll
- the collection to retain
public Object[] toArray()
toArray
in interface Collection<E>
public Object[] toArray(Object[] array)
toArray
in interface Collection<E>
array
- the array to populate
public Set<E> uniqueSet()
uniqueSet
in interface Bag<E>
protected void doWriteObject(ObjectOutputStream out) throws IOException
out
- the output stream
IOException
protected void doReadObject(Map<E,AbstractMapBag.MutableInteger> map, ObjectInputStream in) throws IOException, ClassNotFoundException
map
- the map to usein
- the input stream
IOException
ClassNotFoundException
public boolean equals(Object object)
equals
in interface Collection<E>
equals
in class Object
object
- 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 Collection<E>
hashCode
in class Object
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |