public abstract class DefaultMapBag extends java.lang.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.
Constructor and Description |
---|
DefaultMapBag()
Deprecated.
No-argument constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Object object)
Deprecated.
Adds a new element to the bag by incrementing its count in the
underlying map.
|
boolean |
add(java.lang.Object object,
int nCopies)
Deprecated.
Adds a new element to the bag by incrementing its count in the map.
|
boolean |
addAll(java.util.Collection coll)
Deprecated.
Invokes
add(Object) for each element in the given collection. |
void |
clear()
Deprecated.
Clears the bag by clearing the underlying map.
|
boolean |
contains(java.lang.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(java.util.Collection coll)
Deprecated.
Determines if the bag contains the given elements.
|
boolean |
equals(java.lang.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(java.lang.Object object)
Deprecated.
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
|
int |
hashCode()
Deprecated.
Returns the hash code of the underlying map.
|
boolean |
isEmpty()
Deprecated.
Returns true if the underlying map is empty.
|
java.util.Iterator |
iterator()
Deprecated.
Returns an
Iterator over the entire set of members,
including copies due to cardinality. |
boolean |
remove(java.lang.Object object)
Deprecated.
(Violation)
Removes all occurrences of the given object from the bag.
|
boolean |
remove(java.lang.Object object,
int nCopies)
Deprecated.
Removes
nCopies copies of the specified object from the Bag. |
boolean |
removeAll(java.util.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(java.util.Collection coll)
Deprecated.
Remove any members of the bag that are not in the given
bag, respecting cardinality.
|
int |
size()
Deprecated.
Returns the number of elements in this bag.
|
java.lang.Object[] |
toArray()
Deprecated.
Returns an array of all of this bag's elements.
|
java.lang.Object[] |
toArray(java.lang.Object[] array)
Deprecated.
Returns an array of all of this bag's elements.
|
java.lang.String |
toString()
Deprecated.
Implement a toString() method suitable for debugging.
|
java.util.Set |
uniqueSet()
Deprecated.
Returns an unmodifiable view of the underlying map's key set.
|
public DefaultMapBag()
setMap(Map)
in
their constructors.public boolean add(java.lang.Object object)
public boolean add(java.lang.Object object, int nCopies)
public boolean addAll(java.util.Collection coll)
add(Object)
for each element in the given collection.addAll
in interface java.util.Collection
coll
- the collection to addtrue
if this call changed the bagpublic void clear()
clear
in interface java.util.Collection
public boolean contains(java.lang.Object object)
contains
in interface java.util.Collection
object
- the object to search forpublic boolean containsAll(java.util.Collection coll)
containsAll
in interface java.util.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(java.lang.Object object)
equals
in interface java.util.Collection
equals
in class java.lang.Object
object
- the object to test for equalitypublic int hashCode()
hashCode
in interface java.util.Collection
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public java.util.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(java.lang.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.
public boolean remove(java.lang.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(java.util.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.
public boolean retainAll(java.util.Collection coll)
public boolean retainAll(Bag other)
other
- the bag to retaintrue
if this call changed the collectionretainAll(Collection)
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
public java.lang.Object[] toArray(java.lang.Object[] array)
toArray
in interface java.util.Collection
array
- the array to populatepublic int getCount(java.lang.Object object)
public java.util.Set uniqueSet()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved