public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E>
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 |
AbstractMapMultiSet
Inner class EntrySetIterator.
|
protected static class |
AbstractMapMultiSet
Inner class MultiSetEntry.
|
protected static class |
AbstractMapMultiSet
Mutable integer class for storing the data.
|
protected static class |
AbstractMapMultiSet
Inner class UniqueSetIterator.
|
AbstractMultiSet.AbstractEntry <E>, AbstractMultiSet.EntrySet <E>, AbstractMultiSet.UniqueSet <E> MultiSet.Entry <E> | Modifier | Constructor and Description |
|---|---|
protected |
AbstractMapMultiSet()
Constructor needed for subclass serialisation.
|
protected |
AbstractMapMultiSet(Map
Constructor that assigns the specified Map as the backing store.
|
| Modifier and Type | Method and Description |
|---|---|
int |
add(E object, int occurrences)
Adds a number of occurrences of the specified object to the MultiSet.
|
void |
clear()
Clears the multiset by clearing the underlying map.
|
boolean |
contains(Object
Determines if the multiset contains the given element by checking if the underlying map contains the element as a key.
|
protected Iterator |
createEntrySetIterator()
Creates an entry set iterator.
|
protected Iterator |
createUniqueSetIterator()
Creates a unique set iterator.
|
protected void |
doReadObject(ObjectInputStream
Read the multiset in using a custom routine.
|
protected void |
doWriteObject(ObjectOutputStream
Write the multiset out using a custom routine.
|
boolean |
equals(Object
Compares this MultiSet to another object.
|
int |
getCount(Object
Returns the number of occurrence of the given element in this multiset by looking up its count in the underlying map.
|
protected Map |
getMap()
Utility method for implementations to access the map that backs this multiset.
|
int |
hashCode()
Gets a hash code for the MultiSet compatible with the definition of equals.
|
boolean |
isEmpty()
Returns true if the underlying map is empty.
|
Iterator |
iterator()
Gets an iterator over the multiset elements.
|
int |
remove(Object
Removes a number of occurrences of the specified object from the MultiSet.
|
protected void |
setMap(Map
Sets the map being wrapped.
|
int |
size()
Returns the number of elements in this multiset.
|
Object |
toArray()
Returns an array of all of this multiset's elements.
|
<T> T[] |
toArray(T[] array)
Returns an array of all of this multiset's elements.
|
protected int |
uniqueElements()
Returns the number of unique elements in this multiset.
|
add, createEntrySet, createUniqueSet, entrySet, remove, removeAll, setCount, toString, uniqueSetaddAll, containsAll, retainAllclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, retainAlladdAll, parallelStream, removeIf, spliterator, streamprotected AbstractMapMultiSet()
protected AbstractMapMultiSet(Map<E ,AbstractMapMultiSet .MutableInteger > map)
map - the map to assign
protected Map<E ,AbstractMapMultiSet .MutableInteger > getMap()
protected void setMap(Map<E ,AbstractMapMultiSet .MutableInteger > map)
NOTE: this method should only be used during deserialization
map - the map to wrap
public int size()
size in interface
Collection<E>
size in interface
MultiSet<E>
size in class
AbstractMultiSet<E>
public boolean isEmpty()
isEmpty in interface
Collection<E>
isEmpty in class
AbstractCollection<E>
public int getCount(Objectobject)
public boolean contains(Objectobject)
contains in interface
Collection<E>
contains in class
AbstractMultiSet<E>
object - the object to search for
public Iterator<E> iterator()
public int add(E object, int occurrences)
MultiSet
If the object is already in the MultiSet then increment its count as reported by MultiSet. Otherwise add it to the MultiSet and report its count as occurrences.
add in interface
MultiSet<E>
add in class
AbstractMultiSet<E>
object - the object to add
occurrences - the number of occurrences to add, may be zero, in which case no change is made to the multiset
public void clear()
public int remove(Objectobject, int occurrences)
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.
remove in interface
MultiSet<E>
remove in class
AbstractMultiSet<E>
object - the object to remove
occurrences - the number of occurrences to remove, may be zero, in which case no change is made to the multiset
protected Iterator<E> createUniqueSetIterator()
AbstractMultiSet
createUniqueSetIterator in class
AbstractMultiSet<E>
protected int uniqueElements()
AbstractMultiSet
uniqueElements in class
AbstractMultiSet<E>
protected Iterator<MultiSet .Entry <E>> createEntrySetIterator()
AbstractMultiSet
createEntrySetIterator in class
AbstractMultiSet<E>
protected void doWriteObject(ObjectOutputStreamout) throws IOException
doWriteObject in class
AbstractMultiSet<E>
out - the output stream
IOException - any of the usual I/O related exceptions
protected void doReadObject(ObjectInputStreamin) throws IOException , ClassNotFoundException
doReadObject in class
AbstractMultiSet<E>
in - the input stream
IOException - any of the usual I/O related exceptions
ClassNotFoundException - if the stream contains an object which class can not be loaded
ClassCastException - if the stream does not contain the correct objects
public Object[] toArray()
toArray in interface
Collection<E>
toArray in class
AbstractCollection<E>
public <T> T[] toArray(T[] array)
toArray in interface
Collection<E>
toArray in class
AbstractCollection<E>
T - the type of the array elements
array - the array to populate
ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of the elements in this list
NullPointerException - if the specified array is null
public boolean equals(Objectobject)
MultiSet
This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements.
equals in interface
Collection<E>
equals in interface
MultiSet<E>
equals in class
AbstractMultiSet<E>
object - the object to compare to
public int hashCode()
MultiSet
(e==null ? 0 : e.hashCode()) ^ noOccurances).
hashCode in interface
Collection<E>
hashCode in interface
MultiSet<E>
hashCode in class
AbstractMultiSet<E>