T - public final class Multiset<T> extends Object implements Iterable<T>
Set, but
may have duplicate elements.
Elements of a Multiset that are equal to one another are referred to as
occurrences of the same single element. The total number of
occurrences of an element in a Multiset is called the count of that
element (the terms "frequency" and "multiplicity" are equivalent, but not
used in this API). Since the count of an element is represented as an int, a Multiset may never contain more than MutableInt#MAX_VALUE
occurrences of any one element.
| Constructor and Description |
|---|
Multiset() |
Multiset(Class<? extends Map> valueMapType) |
Multiset(Collection<? extends T> c) |
Multiset(int initialCapacity) |
Multiset(Supplier<? extends Map<T,?>> mapSupplier) |
| Modifier and Type | Method and Description |
|---|---|
<E extends Exception> |
accept(Throwables.Consumer<? super Multiset<T>,E> action) |
<E extends Exception> |
acceptIfNotEmpty(Throwables.Consumer<? super Multiset<T>,E> action)
Accept if not empty.
|
boolean |
add(T e) |
boolean |
add(T e,
int occurrencesToAdd) |
boolean |
addAll(Collection<? extends T> c)
Adds the all.
|
boolean |
addAll(Collection<? extends T> c,
int occurrencesToAdd)
Adds the all.
|
boolean |
addAll(Map<? extends T,Integer> m)
Adds the all.
|
boolean |
addAll(Multiset<? extends T> multiset)
Adds the all.
|
int |
addAndGet(T e)
Adds the and get.
|
int |
addAndGet(T e,
int occurrencesToAdd)
Adds the and get.
|
boolean |
addIfAbsent(T e)
Adds the if absent.
|
boolean |
addIfAbsent(T e,
int occurrencesToAdd)
Adds the if absent.
|
u.Optional<Pair<List<T>,Integer>> |
allMaxOccurrences()
All max occurrences.
|
u.Optional<Pair<List<T>,Integer>> |
allMinOccurrences()
All min occurrences.
|
<R,E extends Exception> |
apply(Throwables.Function<? super Multiset<T>,R,E> func) |
<R,E extends Exception> |
applyIfNotEmpty(Throwables.Function<? super Multiset<T>,R,E> func)
Apply if not empty.
|
u.OptionalDouble |
averageOfOccurrences()
Average of occurrences.
|
void |
clear()
Clear.
|
<E extends Exception> |
compute(T key,
Throwables.BiFunction<? super T,Integer,Integer,E> remappingFunction)
The implementation is equivalent to performing the following steps for this Multiset:
|
<E extends Exception> |
computeIfAbsent(T e,
Throwables.Function<? super T,Integer,E> mappingFunction)
The implementation is equivalent to performing the following steps for this Multiset:
|
<E extends Exception> |
computeIfPresent(T e,
Throwables.BiFunction<? super T,Integer,Integer,E> remappingFunction)
The implementation is equivalent to performing the following steps for this Multiset:
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
Multiset<T> |
copy() |
ImmutableSet<T> |
elements() |
boolean |
equals(Object obj) |
<E extends Exception> |
filter(Throwables.BiPredicate<? super T,Integer,E> filter) |
<E extends Exception> |
filter(Throwables.Predicate<? super T,E> filter) |
Iterator<T> |
flatIterator() |
List<T> |
flatten() |
<E extends Exception> |
forEach(Throwables.Consumer<? super T,E> action) |
<E extends Exception> |
forEach(Throwables.ObjIntConsumer<? super T,E> action) |
static <T> Multiset<T> |
from(Collection<? extends T> coll) |
static <T> Multiset<T> |
from(Iterator<? extends T> iter) |
static <T> Multiset<T> |
from(Map<? extends T,Integer> m) |
int |
get(Object e) |
int |
getAndAdd(T e)
Gets the and add.
|
int |
getAndAdd(T e,
int occurrencesToAdd)
Gets the and add.
|
int |
getAndRemove(Object e)
Gets the and remove.
|
int |
getAndRemove(Object e,
int occurrencesToRemove)
Gets the and remove.
|
int |
getAndSet(T e,
int occurrences)
The element will be removed if the specified count is 0.
|
int |
getOrDefault(Object e,
int defaultValue)
Gets the or default.
|
int |
hashCode() |
boolean |
isEmpty()
Checks if is empty.
|
Iterator<T> |
iterator() |
u.Optional<Pair<T,Integer>> |
maxOccurrences() |
<E extends Exception> |
merge(T key,
int value,
Throwables.BiFunction<Integer,Integer,Integer,E> remappingFunction)
The implementation is equivalent to performing the following steps for this Multiset:
|
u.Optional<Pair<T,Integer>> |
minOccurrences() |
int |
occurrencesOf(Object e) |
static <T> Multiset<T> |
of(T... a) |
boolean |
remove(Object e)
Remove one occurrence from the specified elements.
|
boolean |
remove(Object e,
int occurrencesToRemove)
Remove the specified occurrences from the specified element.
|
boolean |
removeAll(Collection<?> c)
Removes all of this Multiset's elements that are also contained in the
specified collection (optional operation).
|
boolean |
removeAll(Collection<?> c,
int occurrencesToRemove)
Deprecated.
|
boolean |
removeAll(Map<?,Integer> m)
Removes the all.
|
boolean |
removeAll(Multiset<?> multiset)
Removes the all.
|
int |
removeAllOccurrences(Object e)
Removes the all occurrences.
|
<E extends Exception> |
removeAllOccurrencesIf(Throwables.BiPredicate<? super T,? super Integer,E> predicate)
Removes the all occurrences if.
|
<E extends Exception> |
removeAllOccurrencesIf(Throwables.Predicate<? super T,E> predicate)
Removes the all occurrences if.
|
int |
removeAndGet(Object e)
Removes the and get.
|
int |
removeAndGet(Object e,
int occurrencesToRemove)
Removes the and get.
|
<E extends Exception> |
removeIf(int occurrencesToRemove,
Throwables.BiPredicate<? super T,? super Integer,E> predicate)
Removes the if.
|
<E extends Exception> |
removeIf(int occurrencesToRemove,
Throwables.Predicate<? super T,E> predicate)
Removes the if.
|
<E extends Exception> |
replaceAll(Throwables.BiFunction<? super T,? super Integer,Integer,E> function)
The associated elements will be removed if zero or negative occurrences are returned by the specified
function. |
<E extends Exception> |
replaceIf(Throwables.BiPredicate<? super T,? super Integer,E> predicate,
int newOccurrences) |
<E extends Exception> |
replaceIf(Throwables.Predicate<? super T,E> predicate,
int newOccurrences) |
boolean |
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the
specified collection (optional operation).
|
Multiset<T> |
set(T e,
int occurrences)
The element will be removed if the specified count is 0.
|
Multiset<T> |
setAll(Collection<? extends T> c,
int occurrences)
Sets the all.
|
Multiset<T> |
setAll(Map<? extends T,Integer> m)
Sets the all.
|
Multiset<T> |
setAll(Multiset<? extends T> multiset)
Sets the all.
|
int |
setAndGet(T e,
int occurrences)
The element will be removed if the specified count is 0.
|
int |
size() |
long |
sumOfOccurrences()
Sum of occurrences.
|
Object[] |
toArray() |
<A> A[] |
toArray(A[] a) |
ImmutableMap<T,Integer> |
toImmutableMap()
To immutable map.
|
ImmutableMap<T,Integer> |
toImmutableMap(IntFunction<? extends Map<T,Integer>> mapSupplier)
To immutable map.
|
Map<T,Integer> |
toMap() |
<M extends Map<T,Integer>> |
toMap(IntFunction<? extends M> supplier) |
Map<T,Integer> |
toMapSortedByKey(Comparator<? super T> cmp)
To map sorted by key.
|
Map<T,Integer> |
toMapSortedByOccurrences()
To map sorted by occurrences.
|
Map<T,Integer> |
toMapSortedByOccurrences(Comparator<? super Integer> cmp)
To map sorted by occurrences.
|
String |
toString() |
forEach, spliteratorpublic Multiset()
public Multiset(int initialCapacity)
public Multiset(Collection<? extends T> c)
@SafeVarargs public static <T> Multiset<T> of(T... a)
T - a - public static <T> Multiset<T> from(Collection<? extends T> coll)
T - coll - public static <T> Multiset<T> from(Iterator<? extends T> iter)
T - iter - public static <T> Multiset<T> from(Map<? extends T,Integer> m)
T - m - public int get(Object e)
e - public int getOrDefault(Object e, int defaultValue)
e - defaultValue - public int getAndSet(T e, int occurrences)
e - occurrences - public int setAndGet(T e, int occurrences)
e - occurrences - public Multiset<T> set(T e, int occurrences)
e - occurrences - IllegalArgumentException - if the occurrences of element is less than 0public Multiset<T> setAll(Collection<? extends T> c, int occurrences)
c - occurrences - public Multiset<T> setAll(Map<? extends T,Integer> m) throws IllegalArgumentException
m - IllegalArgumentException - if the occurrences of element is less than 0.public Multiset<T> setAll(Multiset<? extends T> multiset) throws IllegalArgumentException
multiset - IllegalArgumentException - if the occurrences of element is less than 0.public int occurrencesOf(Object e)
e - public u.Optional<Pair<T,Integer>> minOccurrences()
public u.Optional<Pair<T,Integer>> maxOccurrences()
public u.Optional<Pair<List<T>,Integer>> allMinOccurrences()
public u.Optional<Pair<List<T>,Integer>> allMaxOccurrences()
public long sumOfOccurrences()
ArithmeticException - if total occurrences overflows the maximum value of int.public u.OptionalDouble averageOfOccurrences()
public boolean add(T e) throws IllegalArgumentException
e - IllegalArgumentException - if the occurrences of element after this operation is bigger than Integer.MAX_VALUE.public boolean add(T e, int occurrencesToAdd) throws IllegalArgumentException
e - occurrencesToAdd - IllegalArgumentException - if the occurrences of element after this operation is bigger than Integer.MAX_VALUE.public boolean addIfAbsent(T e) throws IllegalArgumentException
e - IllegalArgumentException - the illegal argument exceptionpublic boolean addIfAbsent(T e, int occurrencesToAdd) throws IllegalArgumentException
e - occurrencesToAdd - IllegalArgumentException - the illegal argument exceptionpublic int addAndGet(T e)
e - public int addAndGet(T e, int occurrencesToAdd)
e - occurrencesToAdd - public int getAndAdd(T e)
e - public int getAndAdd(T e, int occurrencesToAdd)
e - occurrencesToAdd - public boolean addAll(Collection<? extends T> c) throws IllegalArgumentException
c - IllegalArgumentException - if the occurrences of element after this operation is bigger than Integer.MAX_VALUE.public boolean addAll(Collection<? extends T> c, int occurrencesToAdd) throws IllegalArgumentException
c - occurrencesToAdd - IllegalArgumentException - if the occurrences of element after this operation is bigger than Integer.MAX_VALUE.public boolean addAll(Map<? extends T,Integer> m) throws IllegalArgumentException
m - IllegalArgumentException - if the occurrences of element after this operation is bigger than Integer.MAX_VALUE.public boolean addAll(Multiset<? extends T> multiset) throws IllegalArgumentException
multiset - IllegalArgumentException - if the occurrences of element is less than 0.public boolean contains(Object o)
o - public boolean containsAll(Collection<?> c)
c - public boolean remove(Object e)
Multiset if the occurrences equals to or less than 0 after the operation.e - public boolean remove(Object e, int occurrencesToRemove)
Multiset if the occurrences equals to or less than 0 after the operation.e - occurrencesToRemove - public int removeAndGet(Object e)
e - public int removeAndGet(Object e, int occurrencesToRemove)
e - occurrencesToRemove - public int getAndRemove(Object e)
e - public int getAndRemove(Object e, int occurrencesToRemove)
e - occurrencesToRemove - public int removeAllOccurrences(Object e)
e - public <E extends Exception> boolean removeAllOccurrencesIf(Throwables.Predicate<? super T,E> predicate) throws E extends Exception
E - predicate - E - the eE extends Exceptionpublic <E extends Exception> boolean removeAllOccurrencesIf(Throwables.BiPredicate<? super T,? super Integer,E> predicate) throws E extends Exception
E - predicate - E - the eE extends Exceptionpublic <E extends Exception> boolean removeIf(int occurrencesToRemove, Throwables.Predicate<? super T,E> predicate) throws E extends Exception
E - occurrencesToRemove - predicate - E - the eE extends Exceptionpublic <E extends Exception> boolean removeIf(int occurrencesToRemove, Throwables.BiPredicate<? super T,? super Integer,E> predicate) throws E extends Exception
E - occurrencesToRemove - predicate - E - the eE extends Exceptionpublic boolean removeAll(Collection<?> c)
c, and only cares whether or not an element appears at all.c - Collection.removeAll(Collection)@Deprecated public boolean removeAll(Collection<?> c, int occurrencesToRemove)
c - occurrencesToRemove - the occurrences to remove if the element is in the specified collection c.public boolean removeAll(Multiset<?> multiset) throws IllegalArgumentException
multiset - IllegalArgumentException - the illegal argument exceptionpublic <E extends Exception> boolean replaceIf(Throwables.Predicate<? super T,E> predicate, int newOccurrences) throws E extends Exception
E - predicate - newOccurrences - E - the eE extends Exceptionpublic <E extends Exception> boolean replaceIf(Throwables.BiPredicate<? super T,? super Integer,E> predicate, int newOccurrences) throws E extends Exception
E - predicate - newOccurrences - E - the eE extends Exceptionpublic <E extends Exception> void replaceAll(Throwables.BiFunction<? super T,? super Integer,Integer,E> function) throws E extends Exception
function.E - function - E - the eE extends Exceptionpublic boolean retainAll(Collection<?> c)
c - Collection.retainAll(Collection)public ImmutableSet<T> elements()
public int size()
public boolean isEmpty()
public void clear()
public Object[] toArray()
public <A> A[] toArray(A[] a)
A - a - public <M extends Map<T,Integer>> M toMap(IntFunction<? extends M> supplier)
M - supplier - public Map<T,Integer> toMapSortedByOccurrences()
public Map<T,Integer> toMapSortedByOccurrences(Comparator<? super Integer> cmp)
cmp - public Map<T,Integer> toMapSortedByKey(Comparator<? super T> cmp)
cmp - public ImmutableMap<T,Integer> toImmutableMap()
public ImmutableMap<T,Integer> toImmutableMap(IntFunction<? extends Map<T,Integer>> mapSupplier)
mapSupplier - public List<T> flatten()
Multisetpublic <E extends Exception> Multiset<T> filter(Throwables.Predicate<? super T,E> filter) throws E extends Exception
E - filter - E - the eE extends Exceptionpublic <E extends Exception> Multiset<T> filter(Throwables.BiPredicate<? super T,Integer,E> filter) throws E extends Exception
E - filter - E - the eE extends Exceptionpublic <E extends Exception> void forEach(Throwables.Consumer<? super T,E> action) throws E extends Exception
E - action - E - the eE extends Exceptionpublic <E extends Exception> void forEach(Throwables.ObjIntConsumer<? super T,E> action) throws E extends Exception
E - action - E - the eE extends Exceptionpublic <E extends Exception> int computeIfAbsent(T e, Throwables.Function<? super T,Integer,E> mappingFunction) throws E extends Exception
final int oldValue = get(e);
if (oldValue > 0) {
return oldValue;
}
final int newValue = mappingFunction.apply(e);
if (newValue > 0) {
set(e, newValue);
}
return newValue;
E - e - mappingFunction - E - the eE extends Exceptionpublic <E extends Exception> int computeIfPresent(T e, Throwables.BiFunction<? super T,Integer,Integer,E> remappingFunction) throws E extends Exception
final int oldValue = get(e);
if (oldValue == 0) {
return oldValue;
}
final int newValue = remappingFunction.apply(e, oldValue);
if (newValue > 0) {
set(e, newValue);
} else {
remove(e);
}
return newValue;
E - e - remappingFunction - E - the eE extends Exceptionpublic <E extends Exception> int compute(T key, Throwables.BiFunction<? super T,Integer,Integer,E> remappingFunction) throws E extends Exception
final int oldValue = get(key);
final int newValue = remappingFunction.apply(key, oldValue);
if (newValue > 0) {
set(key, newValue);
} else {
if (oldValue > 0) {
remove(key);
}
}
return newValue;
E - key - remappingFunction - E - the eE extends Exceptionpublic <E extends Exception> int merge(T key, int value, Throwables.BiFunction<Integer,Integer,Integer,E> remappingFunction) throws E extends Exception
int oldValue = get(key);
int newValue = (oldValue == 0) ? value : remappingFunction.apply(oldValue, value);
if (newValue > 0) {
set(key, newValue);
} else {
if (oldValue > 0) {
remove(key);
}
}
return newValue;
E - key - value - remappingFunction - E - the eE extends Exceptionpublic <R,E extends Exception> R apply(Throwables.Function<? super Multiset<T>,R,E> func) throws E extends Exception
R - E - func - E - the eE extends Exceptionpublic <R,E extends Exception> u.Optional<R> applyIfNotEmpty(Throwables.Function<? super Multiset<T>,R,E> func) throws E extends Exception
R - E - func - E - the eE extends Exceptionpublic <E extends Exception> void accept(Throwables.Consumer<? super Multiset<T>,E> action) throws E extends Exception
E - action - E - the eE extends Exceptionpublic <E extends Exception> If.OrElse acceptIfNotEmpty(Throwables.Consumer<? super Multiset<T>,E> action) throws E extends Exception
E - action - E - the eE extends Exceptionpublic boolean equals(Object obj)
Copyright © 2021. All rights reserved.