E
- the type held in the multisetpublic 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.EntrySetIterator<E>
Inner class EntrySetIterator.
|
protected static class |
AbstractMapMultiSet.MultiSetEntry<E>
Inner class MultiSetEntry.
|
protected static class |
AbstractMapMultiSet.MutableInteger
Mutable integer class for storing the data.
|
protected static class |
AbstractMapMultiSet.UniqueSetIterator<E>
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<E,AbstractMapMultiSet.MutableInteger> 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 object)
Determines if the multiset contains the given element by checking if the
underlying map contains the element as a key.
|
protected Iterator<MultiSet.Entry<E>> |
createEntrySetIterator()
Creates an entry set iterator.
|
protected Iterator<E> |
createUniqueSetIterator()
Creates a unique set iterator.
|
protected void |
doReadObject(ObjectInputStream in)
Read the multiset in using a custom routine.
|
protected void |
doWriteObject(ObjectOutputStream out)
Write the multiset out using a custom routine.
|
boolean |
equals(Object object)
Compares this MultiSet to another object.
|
int |
getCount(Object object)
Returns the number of occurrence of the given element in this multiset by
looking up its count in the underlying map.
|
protected Map<E,AbstractMapMultiSet.MutableInteger> |
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<E> |
iterator()
Gets an iterator over the multiset elements.
|
int |
remove(Object object,
int occurrences)
Removes a number of occurrences of the specified object from the MultiSet.
|
protected void |
setMap(Map<E,AbstractMapMultiSet.MutableInteger> 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, uniqueSet
addAll, containsAll, retainAll
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, retainAll
addAll, parallelStream, removeIf, spliterator, stream
protected AbstractMapMultiSet()
protected AbstractMapMultiSet(Map<E,AbstractMapMultiSet.MutableInteger> map)
map
- the map to assignprotected 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 wrappublic 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(Object object)
public boolean contains(Object object)
contains
in interface Collection<E>
contains
in class AbstractMultiSet<E>
object
- the object to search forpublic Iterator<E> iterator()
public int add(E object, int occurrences)
MultiSet
If the object is already in the MultiSet.uniqueSet()
then increment its
count as reported by MultiSet.getCount(Object)
. Otherwise add it to the
MultiSet.uniqueSet()
and report its count as occurrences
.
add
in interface MultiSet<E>
add
in class AbstractMultiSet<E>
object
- the object to addoccurrences
- the number of occurrences to add, may be zero,
in which case no change is made to the multisetpublic void clear()
clear
in interface Collection<E>
clear
in class AbstractMultiSet<E>
public int remove(Object object, 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 removeoccurrences
- the number of occurrences to remove, may be zero,
in which case no change is made to the multisetprotected 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(ObjectOutputStream out) throws IOException
doWriteObject
in class AbstractMultiSet<E>
out
- the output streamIOException
- any of the usual I/O related exceptionsprotected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException
doReadObject
in class AbstractMultiSet<E>
in
- the input streamIOException
- any of the usual I/O related exceptionsClassNotFoundException
- if the stream contains an object which class can not be loadedClassCastException
- if the stream does not contain the correct objectspublic 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 elementsarray
- the array to populateArrayStoreException
- if the runtime type of the specified array is not
a supertype of the runtime type of the elements in this listNullPointerException
- if the specified array is nullpublic boolean equals(Object object)
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 topublic int hashCode()
MultiSet
(e==null ? 0 : e.hashCode()) ^ noOccurances)
.hashCode
in interface Collection<E>
hashCode
in interface MultiSet<E>
hashCode
in class AbstractMultiSet<E>
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.