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.
MultiSet.Entry<E>
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(java.lang.Object object)
Determines if the multiset contains the given element by checking if the
underlying map contains the element as a key.
|
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
looking up its count in the underlying map.
|
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.
|
java.util.Iterator<E> |
iterator()
Gets an iterator over the multiset elements.
|
int |
remove(java.lang.Object object,
int occurrences)
Removes a number of occurrences of the specified object from the MultiSet.
|
int |
size()
Returns the number of elements in this multiset.
|
java.lang.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.
|
add, entrySet, remove, removeAll, setCount, toString, uniqueSet
containsAll, retainAll
public int size()
public boolean isEmpty()
public int getCount(java.lang.Object object)
public boolean contains(java.lang.Object object)
contains
in interface java.util.Collection<E>
contains
in class AbstractMultiSet<E>
object
- the object to search forpublic java.util.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 java.util.Collection<E>
clear
in class AbstractMultiSet<E>
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>
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 multisetpublic java.lang.Object[] toArray()
public <T> T[] toArray(T[] array)
toArray
in interface java.util.Collection<E>
toArray
in class java.util.AbstractCollection<E>
T
- the type of the array elementsarray
- the array to populatejava.lang.ArrayStoreException
- if the runtime type of the specified array is not
a supertype of the runtime type of the elements in this listjava.lang.NullPointerException
- if the specified array is nullpublic 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)
.Copyright © 2010 - 2020 Adobe. All Rights Reserved