E
- the type held in the multisetpublic abstract class AbstractMultiSet<E> extends java.util.AbstractCollection<E> implements MultiSet<E>
MultiSet
interface to simplify the
creation of subclass implementations.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractMultiSet.AbstractEntry<E>
Inner class AbstractEntry.
|
protected static class |
AbstractMultiSet.EntrySet<E>
Inner class EntrySet.
|
private static class |
AbstractMultiSet.MultiSetIterator<E>
Inner class iterator for the MultiSet.
|
protected static class |
AbstractMultiSet.UniqueSet<E>
Inner class UniqueSet.
|
MultiSet.Entry<E>
Modifier and Type | Field and Description |
---|---|
private java.util.Set<MultiSet.Entry<E>> |
entrySet
View of the entries
|
private java.util.Set<E> |
uniqueSet
View of the elements
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractMultiSet()
Constructor needed for subclass serialisation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object)
Adds one copy of the specified object to the MultiSet.
|
int |
add(E object,
int occurrences)
Adds a number of occurrences of the specified object to the MultiSet.
|
void |
clear()
Clears the multiset removing all elements from the entrySet.
|
boolean |
contains(java.lang.Object object)
Determines if the multiset contains the given element.
|
protected java.util.Set<MultiSet.Entry<E>> |
createEntrySet()
Create a new view for the set of entries in this multiset.
|
protected abstract java.util.Iterator<MultiSet.Entry<E>> |
createEntrySetIterator()
Creates an entry set iterator.
|
protected java.util.Set<E> |
createUniqueSet()
Create a new view for the set of unique elements in this multiset.
|
protected java.util.Iterator<E> |
createUniqueSetIterator()
Creates a unique set iterator.
|
protected void |
doReadObject(java.io.ObjectInputStream in)
Read the multiset in using a custom routine.
|
protected void |
doWriteObject(java.io.ObjectOutputStream out)
Write the multiset out using a custom routine.
|
java.util.Set<MultiSet.Entry<E>> |
entrySet()
Returns an unmodifiable view of the entries of this multiset.
|
boolean |
equals(java.lang.Object object)
Compares this MultiSet to another object.
|
int |
getCount(java.lang.Object object)
Returns the number of occurrence of the given element in this multiset by
iterating over its entrySet.
|
int |
hashCode()
Gets a hash code for the MultiSet compatible with the definition of equals.
|
java.util.Iterator<E> |
iterator()
Gets an iterator over the multiset elements.
|
boolean |
remove(java.lang.Object object)
Removes one occurrence of the given object from the MultiSet.
|
int |
remove(java.lang.Object object,
int occurrences)
Removes a number of occurrences of the specified object from the MultiSet.
|
boolean |
removeAll(java.util.Collection<?> coll)
Remove all occurrences of all elements from this MultiSet represented
in the given collection.
|
int |
setCount(E object,
int count)
Sets the number of occurrences of the specified object in the MultiSet
to the given count.
|
int |
size()
Returns the number of elements in this multiset.
|
java.lang.String |
toString()
Implement a toString() method suitable for debugging.
|
protected abstract int |
uniqueElements()
Returns the number of unique elements in this multiset.
|
java.util.Set<E> |
uniqueSet()
Returns a view of the unique elements of this multiset.
|
addAll, containsAll, isEmpty, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, retainAll
private transient java.util.Set<E> uniqueSet
private transient java.util.Set<MultiSet.Entry<E>> entrySet
protected AbstractMultiSet()
public int size()
public int getCount(java.lang.Object object)
public int setCount(E object, int count)
MultiSet
If the provided count is zero, the object will be removed from the
MultiSet.uniqueSet()
.
public boolean contains(java.lang.Object object)
public java.util.Iterator<E> iterator()
public boolean add(E object)
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 1.
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
.
public void clear()
public boolean remove(java.lang.Object object)
MultiSet
If the number of occurrences after this operations is reduced
to zero, the object will be removed from the MultiSet.uniqueSet()
.
public int remove(java.lang.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>
object
- the object to removeoccurrences
- the number of occurrences to remove, may be zero,
in which case no change is made to the multisetpublic boolean removeAll(java.util.Collection<?> coll)
MultiSet
public java.util.Set<E> uniqueSet()
protected java.util.Set<E> createUniqueSet()
protected java.util.Iterator<E> createUniqueSetIterator()
public java.util.Set<MultiSet.Entry<E>> entrySet()
protected java.util.Set<MultiSet.Entry<E>> createEntrySet()
protected abstract int uniqueElements()
protected abstract java.util.Iterator<MultiSet.Entry<E>> createEntrySetIterator()
protected void doWriteObject(java.io.ObjectOutputStream out) throws java.io.IOException
out
- the output streamjava.io.IOException
- any of the usual I/O related exceptionsprotected void doReadObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- the input streamjava.io.IOException
- any of the usual I/O related exceptionsjava.lang.ClassNotFoundException
- if the stream contains an object which class can not be loadedjava.lang.ClassCastException
- if the stream does not contain the correct objectspublic boolean equals(java.lang.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.
public int hashCode()
MultiSet
(e==null ? 0 : e.hashCode()) ^ noOccurances)
.public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>