|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
com.google.common.collect.AbstractMultiset<E>
public abstract class AbstractMultiset<E>
This class provides a skeletal implementation of the Multiset
interface. A new multiset implementation can be created easily by extending
this class and implementing the Multiset.entrySet() method, plus
optionally overriding add(Object, int) and
remove(Object, int) to enable modifications to the multiset.
The contains(java.lang.Object), containsAll(java.util.Collection>), count(java.lang.Object), and
size() implementations all iterate across the set returned by
Multiset.entrySet(), as do many methods acting on the set returned by
elementSet. Override those methods for better performance.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.common.collect.Multiset |
|---|
Multiset.Entry<E> |
| Constructor Summary | |
|---|---|
AbstractMultiset()
|
|
| Method Summary | |
|---|---|
boolean |
add(E element)
|
boolean |
add(E element,
int occurrences)
Adds a number of occurrences of the specified element to this multiset. |
boolean |
addAll(Collection<? extends E> elementsToAdd)
|
void |
clear()
|
boolean |
contains(Object element)
|
boolean |
containsAll(Collection<?> elements)
|
int |
count(Object element)
Returns the number of occurrences of the specified element in this multiset. |
protected Set<E> |
createElementSet()
Creates a new instance of this multiset's element set, which will be returned by elementSet. |
Set<E> |
elementSet()
Returns a view of the elements of this multiset as a set. |
abstract Set<Multiset.Entry<E>> |
entrySet()
Returns the data of this multiset as a set of Entry instances. |
boolean |
equals(Object other)
Compares the specified object with this multiset for equality. |
int |
hashCode()
Returns the hash code for this multiset. |
boolean |
isEmpty()
|
Iterator<E> |
iterator()
|
boolean |
remove(Object element)
|
int |
remove(Object element,
int occurrences)
Removes a number of occurrences of the specified element from this multiset. |
boolean |
removeAll(Collection<?> elementsToRemove)
|
int |
removeAllOccurrences(Object element)
Removes all occurrences of the specified element from this multiset. |
boolean |
retainAll(Collection<?> elementsToRetain)
|
int |
size()
|
String |
toString()
|
| Methods inherited from class java.util.AbstractCollection |
|---|
toArray, toArray |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
toArray, toArray |
| Constructor Detail |
|---|
public AbstractMultiset()
| Method Detail |
|---|
public abstract Set<Multiset.Entry<E>> entrySet()
MultisetEntry instances. This
set contains precisely one Entry instance for each distinct element
of the multiset. The iteration order of this set is
implementation-dependent.
entrySet in interface Multiset<E>public int size()
This implementation iterates across Multiset.entrySet() and
sums the counts of the entries.
size in interface Collection<E>size in class AbstractCollection<E>public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in class AbstractCollection<E>
public boolean contains(@Nullable
Object element)
This implementation checks whether elementSet contains the
element.
contains in interface Collection<E>contains in class AbstractCollection<E>public Iterator<E> iterator()
This implementation usually invokes methods of the
Multiset.entrySet() iterator. As the only exception, the iterator's
remove method sometimes calls the multiset's remove.
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>public int count(Object element)
This implementation iterates across Multiset.entrySet() and
sums the count of all entries.
count in interface Multiset<E>element - the element to look for
Iterables.frequency(java.lang.Iterable>, java.lang.Object)
public boolean add(@Nullable
E element)
This implementation calls add(Object, int) with one occurrence.
add in interface Collection<E>add in class AbstractCollection<E>
public boolean add(E element,
int occurrences)
This implementation always throws an
UnsupportedOperationException. To support adding elements, override
it.
add in interface Multiset<E>element - the element to addoccurrences - the number of occurrences to add
true if the collection changed as a result (this should
always be the case unless occurrences is zero)public boolean remove(Object element)
This implementation calls remove(Object,int) with 1 occurrence.
remove in interface Collection<E>remove in class AbstractCollection<E>
public int remove(Object element,
int occurrences)
This implementation always throws an
UnsupportedOperationException. To support removing elements,
override it.
remove in interface Multiset<E>element - the element whose occurrences should be removedoccurrences - the number of occurrences of this element to remove
public int removeAllOccurrences(Object element)
Multiset.remove(java.lang.Object, int), which removes only one
occurrence at a time.
This implementation calls remove(Object, int) with
Integer.MAX_VALUE occurrences.
removeAllOccurrences in interface Multiset<E>element - the element whose occurrences should all be removed
public boolean containsAll(Collection<?> elements)
This implementation checks whether elementSet contains the
elements.
containsAll in interface Collection<E>containsAll in class AbstractCollection<E>public boolean addAll(Collection<? extends E> elementsToAdd)
If the collection being added is a multiset, this implementation
iterates over that multiset's entry set to add the appropriate number of
occurrences of each of its elements to this multiset. Otherwise, it calls
AbstractCollection.addAll(java.util.Collection extends E>).
addAll in interface Collection<E>addAll in class AbstractCollection<E>public boolean removeAll(Collection<?> elementsToRemove)
This implementation iterates over the elements in the collection and
calls removeAllOccurrences(java.lang.Object) on each element. In some cases, this
approach has better performance than AbstractCollection.removeAll(java.util.Collection>).
removeAll in interface Collection<E>removeAll in class AbstractCollection<E>public boolean retainAll(Collection<?> elementsToRetain)
This implementation iterates over entrySet(), checking each
entry's element to see if it's contained in the provided collection.
If it's not found, the remove method of the entry set's
iterator is invoked. In some cases, this approach has better performance
than AbstractCollection.removeAll(java.util.Collection>).
retainAll in interface Collection<E>retainAll in class AbstractCollection<E>public void clear()
This implementation calls clear on Multiset.entrySet().
clear in interface Collection<E>clear in class AbstractCollection<E>public Set<E> elementSet()
elementSet().size() to find
the number of distinct elements in this multiset.
The returned set's methods are implemented by calling
Multiset.entrySet() methods.
elementSet in interface Multiset<E>protected Set<E> createElementSet()
elementSet.
public boolean equals(@Nullable
Object other)
true if the given object is also a multiset and contains equal
elements with equal counts.
This implementation returns true if other is a multiset
of the same size and if, for each element, the two multisets have the same
count.
equals in interface Multiset<E>equals in interface Collection<E>equals in class Objectpublic int hashCode()
(element == null ? 0 : element.hashCode()) ^ count(element)over all elements in the multiset.
This implementation returns the hash code of Multiset.entrySet().
hashCode in interface Multiset<E>hashCode in interface Collection<E>hashCode in class Objectpublic String toString()
This implementation returns the result of invoking toString on
Multiset.entrySet().
toString in class AbstractCollection<E>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||