|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.collect.ForwardingObject
com.google.common.collect.ForwardingCollection<E>
com.google.common.collect.ForwardingMultiset<E>
com.google.common.collect.LinkedListMultiset<E>
public final class LinkedListMultiset<E>
An implementation of Multiset that supports deterministic iteration
order for elements. The iteration order is preserved across non-distinct
elements. For example,
Multiset<String> m = ...
m.add("a");
m.add("b");
m.add("a");
In this case, the iteration order would be [a, b, a]. Unlike LinkedHashMultiset, the iteration order is kept consistent across
non-distinct elements. For example, calling
map.remove("a");
changes the iteration order to [b, a].
This class provides first(), last() and listIterator() methods on top of the standard Multiset interface.
Note that the performance of this implementation may differ from other
multiset implementations such as HashMultiset. Element addition takes
time and memory proportional to the number of elements being added, even if
those elements are not distinct. Element removal takes constant time if the
element to remove is not contained in the multiset, and otherwise takes time
proportional to the number of elements in the multiset.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.common.collect.Multiset |
|---|
Multiset.Entry<E> |
| Constructor Summary | |
|---|---|
LinkedListMultiset()
Constructs a new empty LinkedListMultiset. |
|
LinkedListMultiset(Iterable<? extends E> elements)
Constructs a new LinkedListMultiset containing the specified
elements. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E e)
|
|
boolean |
add(E e,
int n)
Adds a number of occurrences of the specified element to this multiset. |
|
boolean |
addAll(Collection<? extends E> c)
|
|
void |
clear()
|
|
Set<E> |
elementSet()
Returns a view of the elements of this multiset as a set. |
|
Set<Multiset.Entry<E>> |
entrySet()
Returns the data of this multiset as a set of Entry instances. |
|
E |
first()
Returns the first element in this multiset. |
|
boolean |
isEmpty()
|
|
Iterator<E> |
iterator()
|
|
E |
last()
Returns the last element in this multiset. |
|
ListIterator<E> |
listIterator()
|
|
boolean |
remove(Object e)
|
|
int |
remove(Object e,
int n)
Removes a number of occurrences of the specified element from this multiset. |
|
boolean |
removeAll(Collection<?> c)
|
|
int |
removeAllOccurrences(Object e)
Removes all occurrences of the specified element from this multiset. |
|
boolean |
retainAll(Collection<?> c)
|
|
Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
String |
toString()
|
|
| Methods inherited from class com.google.common.collect.ForwardingMultiset |
|---|
count, delegate, equals, hashCode |
| Methods inherited from class com.google.common.collect.ForwardingCollection |
|---|
contains, containsAll, size |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
contains, containsAll, size |
| Constructor Detail |
|---|
public LinkedListMultiset()
LinkedListMultiset.
public LinkedListMultiset(Iterable<? extends E> elements)
LinkedListMultiset containing the specified
elements.
| Method Detail |
|---|
public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in class ForwardingCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class ForwardingCollection<E>public Object[] toArray()
toArray in interface Collection<E>toArray in class ForwardingCollection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in class ForwardingCollection<E>public E first()
NoSuchElementException - if the multiset is emptypublic E last()
NoSuchElementException - if the multiset is empty
public boolean add(@Nullable
E e)
add in interface Collection<E>add in class ForwardingCollection<E>
public boolean add(@Nullable
E e,
int n)
Multiset
add in interface Multiset<E>add in class ForwardingMultiset<E>e - the element to addn - 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(@Nullable
Object e)
remove in interface Collection<E>remove in class ForwardingCollection<E>
public int remove(@Nullable
Object e,
int n)
Multiset
remove in interface Multiset<E>remove in class ForwardingMultiset<E>e - the element whose occurrences should be removedn - the number of occurrences of this element to remove
public int removeAllOccurrences(@Nullable
Object e)
MultisetMultiset.remove(java.lang.Object, int), which removes only one
occurrence at a time.
removeAllOccurrences in interface Multiset<E>removeAllOccurrences in class ForwardingMultiset<E>e - the element whose occurrences should all be removed
public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in class ForwardingCollection<E>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>removeAll in class ForwardingCollection<E>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>retainAll in class ForwardingCollection<E>public void clear()
clear in interface Collection<E>clear in class ForwardingCollection<E>public ListIterator<E> listIterator()
public Set<E> elementSet()
MultisetelementSet().size() to find
the number of distinct elements in this multiset.
elementSet in interface Multiset<E>elementSet in class ForwardingMultiset<E>public 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>entrySet in class ForwardingMultiset<E>public String toString()
Returns a string representation of this multiset. The string
representation consists of a list of elements in the order returned by
iterator(), enclosed in square brackets ("[]"). Adjacent elements
are separated by the characters ", " (comma and space). Adjacent equal
elements are collapsed; for example, "a, a, a" is represented as "a x 3".
For example:
Multiset<String> multiset = new LinkedListMultiset<String>();
multiset.add("a", 3);
multiset.add("b", 2);
multiset.add("c");
return multiset.toString();
returns the string "[a x 3, b x 2, c]".
toString in class ForwardingObject
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||