|
|||||||||
| 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>
com.google.common.collect.LinkedHashMultiset<E>
public final class LinkedHashMultiset<E>
A Multiset implementation with predictable iteration order. Elements appear in the iterator in order by when the first occurrence of the element was added. If all occurrences of an element are removed, then one or more elements added again, the element will not retain its earlier iteration position, but will appear at the end as if it had never been present.
To preserve iteration order across non-distinct elements, use LinkedListMultiset instead.
LinkedListMultiset,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.common.collect.Multiset |
|---|
Multiset.Entry<E> |
| Constructor Summary | |
|---|---|
LinkedHashMultiset()
Constructs a new empty LinkedHashMultiset using the default initial
capacity (16 distinct elements) and load factor (0.75). |
|
LinkedHashMultiset(int distinctElements)
Constructs a new empty LinkedHashMultiset with the specified
expected number of distinct elements and the default load factor (0.75). |
|
LinkedHashMultiset(Iterable<? extends E> elements)
Constructs a new LinkedHashMultiset containing the specified
elements. |
|
LinkedHashMultiset(Multiset<? extends E> elements)
Constructs a new LinkedHashMultiset containing the specified
elements. |
|
| Method Summary | |
|---|---|
boolean |
add(E element,
int occurrences)
Adds a number of occurrences of the specified element to this multiset. |
protected Map<E,AtomicInteger> |
backingMap()
|
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 AbstractMultiset.elementSet. |
Set<Multiset.Entry<E>> |
entrySet()
Returns the data of this multiset as a set of Entry instances. |
Iterator<E> |
iterator()
|
int |
remove(Object element,
int occurrences)
Removes a number of occurrences of the specified element from this multiset. |
int |
removeAllOccurrences(Object element)
Removes all occurrences of the specified element from this multiset. |
int |
size()
|
| Methods inherited from class com.google.common.collect.AbstractMultiset |
|---|
add, addAll, clear, contains, containsAll, elementSet, equals, hashCode, isEmpty, remove, removeAll, retainAll, 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 LinkedHashMultiset()
LinkedHashMultiset using the default initial
capacity (16 distinct elements) and load factor (0.75).
public LinkedHashMultiset(int distinctElements)
LinkedHashMultiset with the specified
expected number of distinct elements and the default load factor (0.75).
distinctElements - the expected number of distinct elements
IllegalArgumentException - if distinctElements is negativepublic LinkedHashMultiset(Iterable<? extends E> elements)
LinkedHashMultiset containing the specified
elements. If the specified elements is a Multiset instance, this
constructor behaves identically to LinkedHashMultiset(Multiset).
Otherwise, the default initial capacity (16 distinct elements) and load
factor (0.75) is used.
elements - the elements that the multiset should containpublic LinkedHashMultiset(Multiset<? extends E> elements)
LinkedHashMultiset containing the specified
elements. The multiset is created with the default load factor (0.75) and
an initial capacity sufficient to hold the specified elements.
elements - the elements that the multiset should contain| Method Detail |
|---|
protected Map<E,AtomicInteger> backingMap()
public Set<Multiset.Entry<E>> entrySet()
Entry instances. This
set contains precisely one Entry instance for each distinct element
of the multiset. The iteration order of this set is
implementation-dependent.
Invoking Multiset.Entry.getCount() on an entry in the returned
set always returns the current count of that element in the multiset, as
opposed to the count at the time the entry was retrieved.
entrySet in interface Multiset<E>entrySet in class AbstractMultiset<E>public int size()
AbstractMultisetThis implementation iterates across Multiset.entrySet() and
sums the counts of the entries.
size in interface Collection<E>size in class AbstractMultiset<E>public Iterator<E> iterator()
AbstractMultisetThis 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 AbstractMultiset<E>
public int count(@Nullable
Object element)
AbstractMultisetThis implementation iterates across Multiset.entrySet() and
sums the count of all entries.
count in interface Multiset<E>count in class AbstractMultiset<E>element - the element to look for
Iterables.frequency(java.lang.Iterable>, java.lang.Object)
public boolean add(@Nullable
E element,
int occurrences)
This implementation always throws an
UnsupportedOperationException. To support adding elements, override
it.
add in interface Multiset<E>add in class AbstractMultiset<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)
IllegalArgumentException - if the call would result in more than
Integer.MAX_VALUE occurrences of element in this
multiset.
public int remove(@Nullable
Object element,
int occurrences)
AbstractMultisetThis implementation always throws an
UnsupportedOperationException. To support removing elements,
override it.
remove in interface Multiset<E>remove in class AbstractMultiset<E>element - the element whose occurrences should be removedoccurrences - the number of occurrences of this element to remove
public int removeAllOccurrences(@Nullable
Object element)
AbstractMultisetMultiset.remove(java.lang.Object, int), which removes only one
occurrence at a time.
This implementation calls AbstractMultiset.remove(Object, int) with
Integer.MAX_VALUE occurrences.
removeAllOccurrences in interface Multiset<E>removeAllOccurrences in class AbstractMultiset<E>element - the element whose occurrences should all be removed
protected Set<E> createElementSet()
AbstractMultisetAbstractMultiset.elementSet.
createElementSet in class AbstractMultiset<E>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||