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()
Instantiates a new multiset.
|
Multiset(Class<? extends Map> valueMapType)
Instantiates a new multiset.
|
Multiset(Collection<? extends T> c)
Instantiates a new multiset.
|
Multiset(int initialCapacity)
Instantiates a new multiset.
|
Multiset(Supplier<? extends Map<T,?>> mapSupplier)
Instantiates a new multiset.
|
Modifier and Type | Method and Description |
---|---|
<E extends Exception> |
accept(Try.Consumer<? super Multiset<T>,E> action) |
<E extends Exception> |
acceptIfNotEmpty(Try.Consumer<? super Multiset<T>,E> action)
Accept if not empty.
|
boolean |
add(T e) |
boolean |
add(T e,
int occurrences) |
boolean |
addAll(Collection<? extends T> c)
Adds the all.
|
boolean |
addAll(Collection<? extends T> c,
int occurrences)
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 occurrences)
Adds the and get.
|
boolean |
addIfAbsent(T e)
Adds the if absent.
|
boolean |
addIfAbsent(T e,
int occurrences)
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(Try.Function<? super Multiset<T>,R,E> func) |
<R,E extends Exception> |
applyIfNotEmpty(Try.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,
Try.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,
Try.Function<? super T,Integer,E> mappingFunction)
The implementation is equivalent to performing the following steps for this Multiset:
|
<E extends Exception> |
computeIfPresent(T e,
Try.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() |
Set<T> |
elements() |
EntryStream<T,Integer> |
entryStream() |
boolean |
equals(Object obj) |
<E extends Exception> |
filter(Try.BiPredicate<? super T,Integer,E> filter) |
<E extends Exception> |
filter(Try.Predicate<? super T,E> filter) |
Stream<T> |
flatStream() |
List<T> |
flatten() |
<E extends Exception> |
forEach(Try.Consumer<? super T,E> action) |
<E extends Exception> |
forEach(Try.ObjIntConsumer<? super T,E> action) |
static <T> Multiset<T> |
from(Collection<? extends T> coll) |
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 occurrences)
Gets the and add.
|
int |
getAndRemove(Object e)
Gets the and remove.
|
int |
getAndRemove(Object e,
int occurrences)
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,
Try.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 occurrences)
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 occurrences)
Remove the specified occurrences from the specified elements.
|
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(Try.BiPredicate<? super T,? super Integer,E> predicate)
Removes the all occurrences if.
|
<E extends Exception> |
removeAllOccurrencesIf(Try.Predicate<? super T,E> predicate)
Removes the all occurrences if.
|
int |
removeAndGet(Object e)
Removes the and get.
|
int |
removeAndGet(Object e,
int occurrences)
Removes the and get.
|
<E extends Exception> |
removeIf(int occurrences,
Try.BiPredicate<? super T,? super Integer,E> predicate)
Removes the if.
|
<E extends Exception> |
removeIf(int occurrences,
Try.Predicate<? super T,E> predicate)
Removes the if.
|
<E extends Exception> |
replaceAll(Try.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(Try.BiPredicate<? super T,? super Integer,E> predicate,
int newOccurrences) |
<E extends Exception> |
replaceIf(Try.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() |
Stream<T> |
stream() |
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, spliterator
public Multiset()
public Multiset(int initialCapacity)
initialCapacity
- public Multiset(Collection<? extends T> c)
c
- public Multiset(Class<? extends Map> valueMapType)
valueMapType
- @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(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 occurrences) throws IllegalArgumentException
e
- occurrences
- 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 occurrences) throws IllegalArgumentException
e
- occurrences
- IllegalArgumentException
- the illegal argument exceptionpublic int addAndGet(T e)
e
- public int addAndGet(T e, int occurrences)
e
- occurrences
- public int getAndAdd(T e)
e
- public int getAndAdd(T e, int occurrences)
e
- occurrences
- 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 occurrences) throws IllegalArgumentException
c
- occurrences
- 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 occurrences)
Multiset
if the occurrences equals to or less than 0 after the operation.e
- occurrences
- public int removeAndGet(Object e)
e
- public int removeAndGet(Object e, int occurrences)
e
- occurrences
- public int getAndRemove(Object e)
e
- public int getAndRemove(Object e, int occurrences)
e
- occurrences
- public int removeAllOccurrences(Object e)
e
- public <E extends Exception> boolean removeAllOccurrencesIf(Try.Predicate<? super T,E> predicate) throws E extends Exception
E
- predicate
- E
- the eE extends Exception
public <E extends Exception> boolean removeAllOccurrencesIf(Try.BiPredicate<? super T,? super Integer,E> predicate) throws E extends Exception
E
- predicate
- E
- the eE extends Exception
public <E extends Exception> boolean removeIf(int occurrences, Try.Predicate<? super T,E> predicate) throws E extends Exception
E
- occurrences
- predicate
- E
- the eE extends Exception
public <E extends Exception> boolean removeIf(int occurrences, Try.BiPredicate<? super T,? super Integer,E> predicate) throws E extends Exception
E
- occurrences
- predicate
- E
- the eE extends Exception
public boolean removeAll(Collection<?> c)
c
, and only cares whether or not an element appears at all.c
- Collection.removeAll(Collection)
public boolean removeAll(Collection<?> c, int occurrences)
c
- occurrences
- the occurrences to remove if the element is in the specified collection c
.public boolean removeAll(Map<?,Integer> m)
m
- public boolean removeAll(Multiset<?> multiset) throws IllegalArgumentException
multiset
- IllegalArgumentException
- the illegal argument exceptionpublic <E extends Exception> boolean replaceIf(Try.Predicate<? super T,E> predicate, int newOccurrences) throws E extends Exception
E
- predicate
- newOccurrences
- E
- the eE extends Exception
public <E extends Exception> boolean replaceIf(Try.BiPredicate<? super T,? super Integer,E> predicate, int newOccurrences) throws E extends Exception
E
- predicate
- newOccurrences
- E
- the eE extends Exception
public <E extends Exception> void replaceAll(Try.BiFunction<? super T,? super Integer,Integer,E> function) throws E extends Exception
function
.E
- function
- E
- the eE extends Exception
public boolean retainAll(Collection<?> c)
c
- Collection.retainAll(Collection)
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()
Multiset
public <E extends Exception> Multiset<T> filter(Try.Predicate<? super T,E> filter) throws E extends Exception
E
- filter
- E
- the eE extends Exception
public <E extends Exception> Multiset<T> filter(Try.BiPredicate<? super T,Integer,E> filter) throws E extends Exception
E
- filter
- E
- the eE extends Exception
public <E extends Exception> void forEach(Try.Consumer<? super T,E> action) throws E extends Exception
E
- action
- E
- the eE extends Exception
public <E extends Exception> void forEach(Try.ObjIntConsumer<? super T,E> action) throws E extends Exception
E
- action
- E
- the eE extends Exception
public <E extends Exception> int computeIfAbsent(T e, Try.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 Exception
public <E extends Exception> int computeIfPresent(T e, Try.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 Exception
public <E extends Exception> int compute(T key, Try.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 Exception
public <E extends Exception> int merge(T key, int value, Try.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 Exception
public EntryStream<T,Integer> entryStream()
public <R,E extends Exception> R apply(Try.Function<? super Multiset<T>,R,E> func) throws E extends Exception
R
- E
- func
- E
- the eE extends Exception
public <R,E extends Exception> u.Optional<R> applyIfNotEmpty(Try.Function<? super Multiset<T>,R,E> func) throws E extends Exception
R
- E
- func
- E
- the eE extends Exception
public <E extends Exception> void accept(Try.Consumer<? super Multiset<T>,E> action) throws E extends Exception
E
- action
- E
- the eE extends Exception
public <E extends Exception> void acceptIfNotEmpty(Try.Consumer<? super Multiset<T>,E> action) throws E extends Exception
E
- action
- E
- the eE extends Exception
public boolean equals(Object obj)
Copyright © 2019. All rights reserved.