Bag interface to simplify the creation
of subclass implementations.
Subclasses specify a Map implementation to use as the internal storage. 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 and Type | Class and Description |
|---|---|
| pack-priv static class | |
| protected static class | AbstractMapBag.MutableInteger
Mutable integer class for storing the data. |
| Modifier and Type | Field and Description |
|---|---|
| private transient Map | map
The map to use to store the data |
| private transient int | modCount
The modification count for fail fast iterators |
| private int | size
The current total size of the bag |
| private transient Set | uniqueSet
Unique view of the elements |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | AbstractMapBag(final Map<E, AbstractMapBag.
the map to assign mapConstructor that assigns the specified Map as the backing store. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the object was not already in the uniqueSetthe object to add object)Implements org. |
| public boolean | Returns: true if the object was not already in the uniqueSetthe object to search for object, final int the number of copies to add nCopies)Implements org. |
| public boolean | Returns: true if this call changed the bagthe collection to add coll)Implements java. add(Object) for each element in the given collection.
|
| public void | |
| public boolean | Returns: true if the bag contains the given elementthe object to search for object)Implements java. |
| public boolean | Returns: true if the Bag contains all the collectionthe collection to check against coll)Implements org. |
| pack-priv boolean | Returns: true if the Bag contains all the collectionthe bag to check against other)Returns |
| protected void | doReadObject(final Map<E, AbstractMapBag.
the map to use map,the input stream in)Read the map in using a custom routine. |
| protected void | doWriteObject(final ObjectOutputStream
the output stream out)Write the map out using a custom routine. |
| public boolean | Returns: true if equalthe Bag to compare to object)Overrides java. Implements java. |
| public int | Returns: the number of occurrences of the object, zero if not foundthe object to search for object)Implements org. |
| protected Map | Returns: the map being used by the BagUtility method for implementations to access the map that backs this bag. |
| public int | Returns: the hash code of the BagOverrides java. Implements java. |
| public boolean | Returns: true if bag is emptyImplements java. |
| public Iterator | Returns: the iteratorImplements org. |
| public boolean | Returns: true if the bag changedthe object to remove object)Implements org. |
| public boolean | Returns: true if the bag changedthe object to remove object, final int the number of copies to remove nCopies)Implements org. |
| public boolean | Returns: true if the bag changedthe collection to use coll)Implements org. |
| public boolean | Returns: true if this call changed the collectionthe collection to retain coll)Implements org. |
| pack-priv boolean | |
| public int | Returns: current size of the bagImplements org. |
| public Object[] | Returns: an array of all of this bag's elementsImplements java. |
| public < the type of the array elements T> T[] | Returns: an array of all of this bag's elementsthe array to populate array)Implements java. |
| public String | Returns: a debugging toStringOverrides java. |
| public Set | Returns: the set of unique elements in this bagImplements org. |
| map | back to summary |
|---|---|
| private transient Map<E, AbstractMapBag. The map to use to store the data | |
| modCount | back to summary |
|---|---|
| private transient int modCount The modification count for fail fast iterators | |
| size | back to summary |
|---|---|
| private int size The current total size of the bag | |
| uniqueSet | back to summary |
|---|---|
| private transient Set<E> uniqueSet Unique view of the elements | |
| AbstractMapBag | back to summary |
|---|---|
| protected AbstractMapBag() Constructor needed for subclass serialisation. | |
| AbstractMapBag | back to summary |
|---|---|
| protected AbstractMapBag(final Map<E, AbstractMapBag. Constructor that assigns the specified Map as the backing store. The map must be empty and non-null.
| |
| add | back to summary |
|---|---|
| public boolean add(final E object) Implements org. Adds a new element to the bag, incrementing its count in the underlying map.
| |
| add | back to summary |
|---|---|
| public boolean add(final E object, final int nCopies) Implements org. Adds a new element to the bag, incrementing its count in the map.
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(final Collection<? extends E> coll) Implements java. Invokes
| |
| clear | back to summary |
|---|---|
| public void clear() Implements java. Clears the bag by clearing the underlying map.
| |
| contains | back to summary |
|---|---|
| public boolean contains(final Object object) Implements java. Determines if the bag contains the given element by checking if the underlying map contains the element as a key. | |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(final Collection<?> coll) Implements org. Determines if the bag contains the given elements.
| |
| containsAll | back to summary |
|---|---|
| pack-priv boolean containsAll(final Bag<?> other) Returns
| |
| doReadObject | back to summary |
|---|---|
| protected void doReadObject(final Map<E, AbstractMapBag. Read the map in using a custom routine.
| |
| doWriteObject | back to summary |
|---|---|
| protected void doWriteObject(final ObjectOutputStream out) throws IOException Write the map out using a custom routine.
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object object) Overrides java. Implements java. Compares this Bag to another. This Bag equals another Bag if it contains the same number of occurrences of the same elements. | |
| getCount | back to summary |
|---|---|
| public int getCount(final Object object) Implements org. Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map. | |
| getMap | back to summary |
|---|---|
| protected Map Utility method for implementations to access the map that backs this bag. Not intended for interactive use outside of subclasses.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Gets a hash code for the Bag compatible with the definition of equals.
The hash code is defined as the sum total of a hash code for each
element. The per element hash code is defined as
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Returns true if the underlying map is empty.
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements org. Gets an iterator over the bag elements. Elements present in the Bag more than once will be returned repeatedly. | |
| remove | back to summary |
|---|---|
| public boolean remove(final Object object) Implements org. Removes all copies of the specified object from the bag. | |
| remove | back to summary |
|---|---|
| public boolean remove(final Object object, final int nCopies) Implements org. Removes a specified number of copies of an object from the bag. | |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(final Collection<?> coll) Implements org. Removes objects from the bag according to their count in the specified collection.
| |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(final Collection<?> coll) Implements org. Remove any members of the bag that are not in the given bag, respecting cardinality.
| |
| retainAll | back to summary |
|---|---|
| pack-priv boolean retainAll(final Bag<?> other) Remove any members of the bag that are not in the given bag, respecting cardinality.
| |
| size | back to summary |
|---|---|
| public int size() Implements org. Returns the number of elements in this bag.
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Implements java. Returns an array of all of this bag's elements. | |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(T[] array) Implements java. Returns an array of all of this bag's elements. If the input array has more elements than are in the bag, trailing elements will be set to null.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implement a toString() method suitable for debugging. | |
| uniqueSet | back to summary |
|---|---|
| public Set Implements org. Returns an unmodifiable view of the underlying map's key set. | |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private Map. | |
| private final Iterator | |
| private int | |
| private final int | |
| private final AbstractMapBag |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public E | |
| public void | remove()
Overrides default java. |
| canRemove | back to summary |
|---|---|
| private boolean canRemove | |
| current | back to summary |
|---|---|
| private Map. | |
| entryIterator | back to summary |
|---|---|
| private final Iterator<Map. | |
| itemCount | back to summary |
|---|---|
| private int itemCount | |
| mods | back to summary |
|---|---|
| private final int mods | |
| parent | back to summary |
|---|---|
| private final AbstractMapBag<E> parent | |
| BagIterator | back to summary |
|---|---|
| public BagIterator(final AbstractMapBag<E> parent) Constructor.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public E next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |
| Modifier and Type | Field and Description |
|---|---|
| protected int | value
The value of this mutable. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(final Object
the reference object with which to compare. obj)Overrides java. |
| public int |
| value | back to summary |
|---|---|
| protected int value The value of this mutable. | |
| MutableInteger | back to summary |
|---|---|
| pack-priv MutableInteger(final int value) Constructor.
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |