public abstract class DefaultMapBag extends Object implements Bag
Bag
interface to minimize the effort required for target implementations.
Subclasses need only to call setMap(Map)
in their constructor
(or invoke the Map 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.
Modifier | Constructor and Description |
---|---|
|
DefaultMapBag()
Deprecated.
No-argument constructor.
|
protected |
DefaultMapBag(Map map)
Deprecated.
Constructor that assigns the specified Map as the backing store.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object object)
Deprecated.
Adds a new element to the bag by incrementing its count in the
underlying map.
|
boolean |
add(Object object,
int nCopies)
Deprecated.
Adds a new element to the bag by incrementing its count in the map.
|
boolean |
addAll(Collection coll)
Deprecated.
Invokes
add(Object) for each element in the given collection. |
protected int |
calcTotalSize()
Deprecated.
Actually walks the bag to make sure the count is correct and
resets the running total
|
void |
clear()
Deprecated.
Clears the bag by clearing the underlying map.
|
boolean |
contains(Object object)
Deprecated.
Determines if the bag contains the given element by checking if the
underlying map contains the element as a key.
|
boolean |
containsAll(Bag other)
Deprecated.
Returns
true if the bag contains all elements in
the given collection, respecting cardinality. |
boolean |
containsAll(Collection coll)
Deprecated.
Determines if the bag contains the given elements.
|
boolean |
equals(Object object)
Deprecated.
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.
|
int |
getCount(Object object)
Deprecated.
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
|
protected Map |
getMap()
Deprecated.
Utility method for implementations to access the map that backs
this bag.
|
int |
hashCode()
Deprecated.
Returns the hash code of the underlying map.
|
boolean |
isEmpty()
Deprecated.
Returns true if the underlying map is empty.
|
Iterator |
iterator()
Deprecated.
Returns an
Iterator over the entire set of members,
including copies due to cardinality. |
boolean |
remove(Object object)
Deprecated.
(Violation)
Removes all occurrences of the given object from the bag.
|
boolean |
remove(Object object,
int nCopies)
Deprecated.
Removes
nCopies copies of the specified object from the Bag. |
boolean |
removeAll(Collection coll)
Deprecated.
(Violation)
Remove all elements represented in the given collection,
respecting cardinality.
|
boolean |
retainAll(Bag other)
Deprecated.
Remove any members of the bag that are not in the given
bag, respecting cardinality.
|
boolean |
retainAll(Collection coll)
Deprecated.
Remove any members of the bag that are not in the given
bag, respecting cardinality.
|
protected void |
setMap(Map map)
Deprecated.
Utility method for implementations to set the map that backs
this bag.
|
int |
size()
Deprecated.
Returns the number of elements in this bag.
|
Object[] |
toArray()
Deprecated.
Returns an array of all of this bag's elements.
|
Object[] |
toArray(Object[] array)
Deprecated.
Returns an array of all of this bag's elements.
|
String |
toString()
Deprecated.
Implement a toString() method suitable for debugging.
|
Set |
uniqueSet()
Deprecated.
Returns an unmodifiable view of the underlying map's key set.
|
public DefaultMapBag()
setMap(Map)
in
their constructors.protected DefaultMapBag(Map map)
map
- the map to assignpublic boolean add(Object object)
add
in interface Collection
add
in interface Bag
object
- the object to addtrue
if the object was not already in the uniqueSet
public boolean add(Object object, int nCopies)
public boolean addAll(Collection coll)
add(Object)
for each element in the given collection.addAll
in interface Collection
coll
- the collection to addtrue
if this call changed the bagpublic void clear()
clear
in interface Collection
public boolean contains(Object object)
contains
in interface Collection
object
- the object to search forpublic boolean containsAll(Collection coll)
containsAll
in interface Collection
containsAll
in interface Bag
coll
- the collection to check againsttrue
if the Bag contains all the collectionpublic boolean containsAll(Bag other)
true
if the bag contains all elements in
the given collection, respecting cardinality.other
- the bag to check againsttrue
if the Bag contains all the collectionpublic boolean equals(Object object)
equals
in interface Collection
equals
in class Object
object
- the object to test for equalitypublic int hashCode()
hashCode
in interface Collection
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection
public Iterator iterator()
Bag
Iterator
over the entire set of members,
including copies due to cardinality. This iterator is fail-fast
and will not tolerate concurrent modifications.public boolean remove(Object object)
Bag
This will also remove the object from the Bag.uniqueSet()
.
According to the Collection.remove(Object)
method,
this method should only remove the first occurrence of the
given object, not all occurrences.
remove
in interface Collection
remove
in interface Bag
true
if this call changed the collectionpublic boolean remove(Object object, int nCopies)
Bag
nCopies
copies of the specified object from the Bag.
If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.
public boolean removeAll(Collection coll)
Bag
coll
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.
removeAll
in interface Collection
removeAll
in interface Bag
coll
- the collection to removetrue
if this call changed the collectionpublic boolean retainAll(Collection coll)
retainAll
in interface Collection
retainAll
in interface Bag
coll
- the collection to retainpublic boolean retainAll(Bag other)
other
- the bag to retaintrue
if this call changed the collectionretainAll(Collection)
public Object[] toArray()
toArray
in interface Collection
public Object[] toArray(Object[] array)
toArray
in interface Collection
array
- the array to populatepublic int getCount(Object object)
public Set uniqueSet()
public int size()
size
in interface Collection
size
in interface Bag
protected int calcTotalSize()
protected void setMap(Map map)
protected Map getMap()
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.