public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implements MultiSet <E>
MultiSet interface to simplify the creation of subclass implementations.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractMultiSet
Inner class AbstractEntry.
|
protected static class |
AbstractMultiSet
Inner class EntrySet.
|
protected static class |
AbstractMultiSet
Inner class UniqueSet.
|
MultiSet.Entry <E> | 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(Object
Determines if the multiset contains the given element.
|
protected Set |
createEntrySet()
Create a new view for the set of entries in this multiset.
|
protected abstract Iterator |
createEntrySetIterator()
Creates an entry set iterator.
|
protected Set |
createUniqueSet()
Create a new view for the set of unique elements in this multiset.
|
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.
|
Set |
entrySet()
Returns an unmodifiable view of the entries of this multiset.
|
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 iterating over its entrySet.
|
int |
hashCode()
Gets a hash code for the MultiSet compatible with the definition of equals.
|
Iterator |
iterator()
Gets an iterator over the multiset elements.
|
boolean |
remove(Object
Removes one occurrence of the given object from the MultiSet.
|
int |
remove(Object
Removes a number of occurrences of the specified object from the MultiSet.
|
boolean |
removeAll(Collection
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.
|
String |
toString()
Implement a toString() method suitable for debugging.
|
protected abstract int |
uniqueElements()
Returns the number of unique elements in this multiset.
|
Set |
uniqueSet()
Returns a view of the unique elements of this multiset.
|
addAll, containsAll, isEmpty, retainAll, toArray, toArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, retainAlladdAll, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArrayprotected AbstractMultiSet()
public int size()
size in interface
Collection<E>
size in interface
MultiSet<E>
size in class
AbstractCollection<E>
public int getCount(Objectobject)
public int setCount(E object, int count)
MultiSet
If the provided count is zero, the object will be removed from the MultiSet.
public boolean contains(Objectobject)
contains in interface
Collection<E>
contains in class
AbstractCollection<E>
object - the object to search for
public Iterator<E> iterator()
public boolean add(E object)
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 1.
add in interface
Collection<E>
add in interface
MultiSet<E>
add in class
AbstractCollection<E>
object - the object to add
true always, as the size of the MultiSet is increased in any case
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.
public void clear()
public boolean remove(Objectobject)
MultiSet
If the number of occurrences after this operations is reduced to zero, the object will be removed from the MultiSet.
remove in interface
Collection<E>
remove in interface
MultiSet<E>
remove in class
AbstractCollection<E>
object - the object to remove
true if this call changed the collection
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>
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
public boolean removeAll(Collection<?> coll)
MultiSet
removeAll in interface
Collection<E>
removeAll in interface
MultiSet<E>
removeAll in class
AbstractCollection<E>
coll - the collection of elements to remove
true if this call changed the multiset
protected Set<E> createUniqueSet()
protected Iterator<E> createUniqueSetIterator()
public Set<MultiSet .Entry <E>> entrySet()
protected Set<MultiSet .Entry <E>> createEntrySet()
protected abstract int uniqueElements()
protected abstract Iterator<MultiSet .Entry <E>> createEntrySetIterator()
protected void doWriteObject(ObjectOutputStreamout) throws IOException
out - the output stream
IOException - any of the usual I/O related exceptions
protected void doReadObject(ObjectInputStreamin) throws IOException , ClassNotFoundException
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 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.
public int hashCode()
MultiSet
(e==null ? 0 : e.hashCode()) ^ noOccurances).
public StringtoString()
toString in class
AbstractCollection<E>