MultiSet 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 multiset elements to a number; the number represents the number of occurrences of that element in the multiset.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | |
| private static class | |
| protected static class | |
| protected static class | AbstractMapMultiSet.MutableInteger
Mutable integer class for storing the data. |
| protected static class |
| 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 transient int | size
The current total size of the multiset |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | AbstractMapMultiSet(final Map<E, AbstractMapMultiSet.
the map to assign mapConstructor that assigns the specified Map as the backing store. |
| Modifier and Type | Method and Description |
|---|---|
| public int | add(final E
the object to add object, final int the number of occurrences to add, may be zero,
in which case no change is made to the multiset occurrences)Overrides org. Implements org. |
| public void | clear()
Overrides org. Implements java. |
| public boolean | Returns: true if the multiset contains the given elementthe object to search for object)Overrides org. Implements java. |
| protected Iterator | createEntrySetIterator()
Implements abstract org. |
| protected Iterator | createUniqueSetIterator()
Overrides org. |
| protected void | doReadObject(final ObjectInputStream
the input stream in)Overrides org. |
| protected void | doWriteObject(final ObjectOutputStream
the output stream out)Overrides org. |
| public boolean | equals(final Object
the object to compare to object)Overrides org. Implements org. |
| public int | Returns: the number of occurrences of the object, zero if not foundthe object to search for object)Overrides org. Implements org. |
| protected Map | Returns: the map being used by the MultiSetUtility method for implementations to access the map that backs this multiset. |
| public int | hashCode()
Overrides org. Implements org. |
| public boolean | Returns: true if multiset is emptyOverrides java. Implements java. |
| public Iterator | Returns: the iteratorOverrides org. Implements org. |
| public int | remove(final Object
the object to remove object, final int the number of occurrences to remove, may be zero,
in which case no change is made to the multiset occurrences)Overrides org. Implements org. |
| protected void | setMap(final Map<E, AbstractMapMultiSet.
the map to wrap mapSets the map being wrapped. |
| public int | Returns: current size of the multisetOverrides org. Implements org. |
| public Object[] | Returns: an array of all of this multiset's elementsOverrides java. Implements java. |
| public < the type of the array elements T> T[] | Returns: an array of all of this multiset's elementsthe array to populate array)Overrides java. Implements java. |
| protected int | uniqueElements()
Implements abstract org. |
| map | back to summary |
|---|---|
| private transient Map<E, AbstractMapMultiSet. 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 transient int size The current total size of the multiset | |
| AbstractMapMultiSet | back to summary |
|---|---|
| protected AbstractMapMultiSet() Constructor needed for subclass serialisation. | |
| AbstractMapMultiSet | back to summary |
|---|---|
| protected AbstractMapMultiSet(final Map<E, AbstractMapMultiSet. Constructor that assigns the specified Map as the backing store. The map must be empty and non-null.
| |
| add | back to summary |
|---|---|
| public int add(final E object, final int occurrences) Overrides org. Implements org. Doc from org. Adds a number of occurrences of the specified object to the MultiSet.
If the object is already in the
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides org. Implements java. Clears the multiset by clearing the underlying map.
| |
| contains | back to summary |
|---|---|
| public boolean contains(final Object object) Overrides org. Implements java. Determines if the multiset contains the given element by checking if the underlying map contains the element as a key. | |
| createEntrySetIterator | back to summary |
|---|---|
| protected Iterator Implements abstract org. Doc from org. Creates an entry set iterator. Subclasses can override this to return iterators with different properties. | |
| createUniqueSetIterator | back to summary |
|---|---|
| protected Iterator Overrides org. Doc from org. Creates a unique set iterator. Subclasses can override this to return iterators with different properties. | |
| doReadObject | back to summary |
|---|---|
| protected void doReadObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Overrides org. Read the multiset in using a custom routine.
| |
| doWriteObject | back to summary |
|---|---|
| protected void doWriteObject(final ObjectOutputStream out) throws IOException Overrides org. Write the multiset out using a custom routine.
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object object) Overrides org. Implements org. Doc from org. Compares this MultiSet to another object. This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements. | |
| getCount | back to summary |
|---|---|
| public int getCount(final Object object) Overrides org. Implements org. Returns the number of occurrence of the given element in this multiset 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 multiset. Not intended for interactive use outside of subclasses.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. Implements org. Doc from org. Gets a hash code for the MultiSet 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() Overrides java. Implements java. Returns true if the underlying map is empty.
| |
| iterator | back to summary |
|---|---|
| public Iterator Overrides org. Implements org. Gets an iterator over the multiset elements. Elements present in the MultiSet more than once will be returned repeatedly. | |
| remove | back to summary |
|---|---|
| public int remove(final Object object, final int occurrences) Overrides org. Implements org. Doc from org. Removes a number of occurrences of the specified object from the MultiSet. If the number of occurrences to remove is greater than the actual number of occurrences in the multiset, the object will be removed from the multiset. | |
| setMap | back to summary |
|---|---|
| protected void setMap(final Map<E, AbstractMapMultiSet. Sets the map being wrapped. Note this method should only be used during deserialization
| |
| size | back to summary |
|---|---|
| public int size() Overrides org. Implements org. Returns the number of elements in this multiset.
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Overrides java. Implements java. Returns an array of all of this multiset's elements. | |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(T[] array) Overrides java. Implements java. Returns an array of all of this multiset's elements. If the input array has more elements than are in the multiset, trailing elements will be set to null.
| |
| uniqueElements | back to summary |
|---|---|
| protected int uniqueElements() Implements abstract org. Doc from org. Returns the number of unique elements in this multiset.
| |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | canRemove
Whether remove is allowed at present |
| protected final Iterator | |
| protected MultiSet. | last
The last returned entry |
| protected final AbstractMapMultiSet | parent
The parent map |
| Access | Constructor and Description |
|---|---|
| protected | EntrySetIterator(final Iterator<Map.
the iterator to decorate iterator,the parent multiset parent)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public MultiSet. | |
| public void | remove()
Overrides default java. |
| canRemove | back to summary |
|---|---|
| protected boolean canRemove Whether remove is allowed at present | |
| decorated | back to summary |
|---|---|
| protected final Iterator<Map. | |
| last | back to summary |
|---|---|
| protected MultiSet. The last returned entry | |
| parent | back to summary |
|---|---|
| protected final AbstractMapMultiSet<E> parent The parent map | |
| EntrySetIterator | back to summary |
|---|---|
| protected EntrySetIterator(final Iterator<Map. Constructor.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public MultiSet. 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 |
|---|---|
| private boolean | |
| private Map. | |
| private final Iterator | |
| private int | |
| private final int | |
| private final AbstractMapMultiSet |
| 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 AbstractMapMultiSet<E> parent | |
| MapBasedMultiSetIterator | back to summary |
|---|---|
| public MapBasedMultiSetIterator(final AbstractMapMultiSet<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 final Map. |
| Access | Constructor and Description |
|---|---|
| protected | MultiSetEntry(final Map.
the entry to decorate parentEntryConstructor. |
| Modifier and Type | Method and Description |
|---|---|
| public int | getCount()
Implements org. |
| public E | getElement()
Implements org. |
| parentEntry | back to summary |
|---|---|
| protected final Map. | |
| MultiSetEntry | back to summary |
|---|---|
| protected MultiSetEntry(final Map. Constructor.
| |
| getCount | back to summary |
|---|---|
| public int getCount() Implements org. Doc from org. Returns the number of occurrences for the element of this entry.
| |
| getElement | back to summary |
|---|---|
| public E getElement() Implements org. Doc from org. Returns the element corresponding to this entry.
| |
| 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
| |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | canRemove
Whether remove is allowed at present |
| protected E | lastElement
The last returned element |
| protected final AbstractMapMultiSet | parent
The parent multiset |
| Access | Constructor and Description |
|---|---|
| protected | UniqueSetIterator(final Iterator<E>
the iterator to decorate iterator, final AbstractMapMultiSet<E> the parent multiset parent)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public E | next()
Overrides org. Implements java. |
| public void | remove()
Overrides org. Overrides default java. |
| canRemove | back to summary |
|---|---|
| protected boolean canRemove Whether remove is allowed at present | |
| lastElement | back to summary |
|---|---|
| protected E lastElement The last returned element | |
| parent | back to summary |
|---|---|
| protected final AbstractMapMultiSet<E> parent The parent multiset | |
| UniqueSetIterator | back to summary |
|---|---|
| protected UniqueSetIterator(final Iterator<E> iterator, final AbstractMapMultiSet<E> parent) Constructor.
| |
| next | back to summary |
|---|---|
| public E next() Overrides org. Implements java. Doc from org. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides org. 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
| |