Uses of Interface
com.google.mu.util.stream.BiCollector
Package
Description
Google Protobuf utilities (requires mug-protobuf artifact)
BiStream, BiCollector, MoreStreams, MoreCollectors etc.
-
Uses of BiCollector in com.google.mu.protobuf.util
Modifier and TypeMethodDescriptionstatic BiCollector
<CharSequence, com.google.protobuf.Value, com.google.protobuf.Struct> MoreStructs.toStruct()
Returns aBiCollector
that collects the input key-value pairs intoStruct
.final BiCollector
<CharSequence, Object, com.google.protobuf.Struct> Structor.toStruct()
Returns aBiCollector
that accumulates the name-value pairs into aStruct
with the values converted usingStructor.toValue(java.lang.Object)
. -
Uses of BiCollector in com.google.mu.util.stream
Modifier and TypeMethodDescriptionstatic <K,
V> BiCollector <K, V, Double> BiCollectors.averagingDouble
(ToDoubleBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the arithmetic mean of a double-valued function applied to the input pair.static <K,
V> BiCollector <K, V, Double> BiCollectors.averagingInt
(ToIntBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the arithmetic mean of an integer-valued function applied to the input pair.static <K,
V> BiCollector <K, V, Double> BiCollectors.averagingLong
(ToLongBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the arithmetic mean of a long-valued function applied to the input pair.static <K,
V, A, B, R>
BiCollector<K, V, R> BiCollectors.collectingAndThen
(BiCollector<K, V, ? extends Both<? extends A, ? extends B>> collector, BiFunction<? super A, ? super B, ? extends R> finisher) static <K,
V, T, R>
BiCollector<K, V, R> BiCollectors.collectingAndThen
(BiCollector<K, V, T> upstream, Function<? super T, ? extends R> finisher) static <K,
V, R> BiCollector <K, V, R> BiCollectors.collectingAndThen
(Function<? super BiStream<K, V>, ? extends R> finisher) Returns aBiCollector
that first collects the input pairs into aBiStream
and then appliesfinisher
on the intermediary BiStream.static <K,
V> BiCollector <K, V, Long> BiCollectors.counting()
Returns a countingBiCollector
that counts the number of input entries.static <K,
V> BiCollector <K, V, Integer> BiCollectors.countingDistinct()
Returns a countingBiCollector
that counts the number of distinct input entries according toObject.equals(java.lang.Object)
for both keys and values.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.flatMapping
(BiFunction<? super K, ? super V, ? extends BiStream<? extends K1, ? extends V1>> flattener, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first flattens the input pair usingflattener
and then collects the result pairs usingdownstream
collector.static <K,
V, T, R>
BiCollector<K, V, R> BiCollectors.flatMapping
(BiFunction<? super K, ? super V, ? extends Stream<? extends T>> flattener, Collector<T, ?, R> downstream) Returns aBiCollector
that first flattens the input pair usingflattener
and then collects the results usingdownstream
collector.static <K,
T, V> BiCollector <K, T, com.google.common.collect.ImmutableListMultimap<K, V>> GuavaCollectors.flatteningToImmutableListMultimap
(Function<? super T, ? extends Stream<? extends V>> flattener) Returns aBiCollector
that first flattens each value of the input pair withflattener
, and then collects the flattened pairs into anImmutableListMultimap
.static <K,
T, V> BiCollector <K, T, com.google.common.collect.ImmutableSetMultimap<K, V>> GuavaCollectors.flatteningToImmutableSetMultimap
(Function<? super T, ? extends Stream<? extends V>> flattener) Returns aBiCollector
that first flattens each value of the input pair withflattener
, and then collects the flattened pairs into anImmutableSetMultimap
.static <R,
C, V> BiCollector <C, V, BiStream<R, BiStream<C, V>>> BiCollectors.groupingBy
(BiFunction<? super C, ? super V, ? extends R> classifier) Groups input pairs byclassifier
and collects entries belonging to the same group into a nestedBiStream
.static <K,
V, G, R>
BiCollector<K, V, BiStream<G, R>> BiCollectors.groupingBy
(BiFunction<? super K, ? super V, ? extends G> classifier, BiCollector<? super K, ? super V, R> groupCollector) Groups input entries byclassifier
and collects entries belonging to the same group usinggroupCollector
.static <K,
V, G> BiCollector <K, V, BiStream<G, V>> BiCollectors.groupingBy
(Function<? super K, ? extends G> classifier, BinaryOperator<V> groupReducer) Groups input pairs byclassifier
and reduces values belonging to the same group usinggroupReducer
.static <K,
V, G, R>
BiCollector<K, V, BiStream<G, R>> BiCollectors.groupingBy
(Function<? super K, ? extends G> classifier, Collector<? super V, ?, R> groupCollector) Groups input entries byclassifier
and collects values belonging to the same group usinggroupCollector
.static <A,
B, R> BiCollector <A, B, R> BiCollectors.inverse
(BiCollector<B, A, R> downstream) Returns a BiCollector that inverses the input pairs of(a, b)
into(b, a)
before passing it todownstream
collector.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(BiFunction<? super K, ? super V, ? extends Both<? extends K1, ? extends V1>> mapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair into another pair usingmapper
.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(BiFunction<? super K, ? super V, ? extends K1> keyMapper, BiFunction<? super K, ? super V, ? extends V1> valueMapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair usingkeyMapper
andvalueMapper
respectively, then collects the results usingdownstream
collector.static <K,
V, T, R>
BiCollector<K, V, R> BiCollectors.mapping
(BiFunction<? super K, ? super V, ? extends T> mapper, Collector<T, ?, R> downstream) Returns aBiCollector
that first maps the input pair usingmapper
and then collects the results usingdownstream
collector.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(Function<? super K, ? extends K1> keyMapper, Function<? super V, ? extends V1> valueMapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair usingkeyMapper
andvalueMapper
, then collects the results using thedownstream
collector.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.maxBy
(Comparator<? super K> keyComparator, Comparator<? super V> valueComparator) Returns aBiCollector
that finds the maximum pair according tokeyComparator
and thenvalueComparator
for equal keys.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.maxByKey
(Comparator<? super K> comparator) Returns aBiCollector
that finds the pair with the maximum key according tocomparator
.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.maxByValue
(Comparator<? super V> comparator) Returns aBiCollector
that finds the pair with the maximum value according tocomparator
.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.minBy
(Comparator<? super K> keyComparator, Comparator<? super V> valueComparator) Returns aBiCollector
that finds the minimum pair according tokeyComparator
and thenvalueComparator
for equal keys.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.minByKey
(Comparator<? super K> comparator) Returns aBiCollector
that finds the pair with the minimum key according tocomparator
.static <K,
V> BiCollector <K, V, BiOptional<K, V>> BiCollectors.minByValue
(Comparator<? super V> comparator) Returns aBiCollector
that finds the pair with the minimum value according tocomparator
.static <K,
V> BiCollector <K, V, Both<BiStream<K, V>, BiStream<K, V>>> BiCollectors.partitioningBy
(BiPredicate<? super K, ? super V> predicate) Returns a BiCollector that partitions the incoming pairs into two groups: elements that matchpredicate
, and those that don't.static <K,
V, R> BiCollector <K, V, Both<R, R>> BiCollectors.partitioningBy
(BiPredicate<? super K, ? super V> predicate, BiCollector<? super K, ? super V, ? extends R> downstream) Returns a BiCollector that partitions the incoming pairs into two groups: elements that matchpredicate
, and those that don't, and usedownstream
collector to collect the pairs.static <K,
V, T, F>
BiCollector<K, V, Both<T, F>> BiCollectors.partitioningBy
(BiPredicate<? super K, ? super V> predicate, BiCollector<? super K, ? super V, ? extends T> ifTrue, BiCollector<? super K, ? super V, ? extends F> ifFalse) Returns a BiCollector that partitions the incoming pairs into two groups: elements that matchpredicate
, and those that don't, and useifTrue
andifFalse
downstream collectors respectively to collect the pairs.static <K,
V> BiCollector <K, V, DoubleSummaryStatistics> BiCollectors.summarizingDouble
(ToDoubleBiFunction<? super K, ? super V> mapper) Returns aBiCollector
which applies andouble
-producing mapping function to each input pair, and returns summary statistics for the resulting values.static <K,
V> BiCollector <K, V, IntSummaryStatistics> BiCollectors.summarizingInt
(ToIntBiFunction<? super K, ? super V> mapper) Returns aBiCollector
which applies anint
-producing mapping function to each input pair, and returns summary statistics for the resulting values.static <K,
V> BiCollector <K, V, LongSummaryStatistics> BiCollectors.summarizingLong
(ToLongBiFunction<? super K, ? super V> mapper) Returns aBiCollector
which applies anlong
-producing mapping function to each input pair, and returns summary statistics for the resulting values.static <K,
V> BiCollector <K, V, Double> BiCollectors.summingDouble
(ToDoubleBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the sum of a double-valued function applied to the input pair.static <K,
V> BiCollector <K, V, Integer> BiCollectors.summingInt
(ToIntBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the sum of an integer-valued function applied to the input pair.static <K,
V> BiCollector <K, V, Long> BiCollectors.summingLong
(ToLongBiFunction<? super K, ? super V> mapper) Returns aBiCollector
that produces the sum of a long-valued function applied to the input pair.static <K extends Comparable<K>,
V>
BiCollector<com.google.common.collect.Range<K>, V, BiStream<com.google.common.collect.Range<K>, Chain<V>>> GuavaCollectors.toDisjointRanges()
Returns a BiCollector that merges values mapped to overlapping ranges into aChain
, which is an immutableList
that may have been deeplyconcatenated
.static <K extends Comparable<K>,
V>
BiCollector<com.google.common.collect.Range<K>, V, BiStream<com.google.common.collect.Range<K>, V>> GuavaCollectors.toDisjointRanges
(BinaryOperator<V> merger) Returns a BiCollector that merges values mapped to overlapping ranges using themerger
function and builds aBiStream
with disjoint ranges and the corresponding merged values.static <K extends Comparable<K>,
V, R>
BiCollector<com.google.common.collect.Range<K>, V, BiStream<com.google.common.collect.Range<K>, R>> GuavaCollectors.toDisjointRanges
(Collector<V, ?, R> valueCollector) Returns a BiCollector that collects values mapped to overlapping ranges usingvalueCollector
, and builds aBiStream
with disjoint ranges and the corresponding collector results.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableBiMap<K, V>> GuavaCollectors.toImmutableBiMap()
Returns aBiCollector
that collects the key-value pairs into anImmutableBiMap
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableListMultimap<K, V>> GuavaCollectors.toImmutableListMultimap()
Returns aBiCollector
that collects the key-value pairs into anImmutableListMultimap
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableMap<K, V>> GuavaCollectors.toImmutableMap()
Returns aBiCollector
that collects the key-value pairs into anImmutableMap
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableMap<K, V>> GuavaCollectors.toImmutableMap
(BinaryOperator<V> valueMerger) Returns aBiCollector
that collects the key-value pairs into anImmutableMap
usingvalueMerger
to merge values of duplicate keys.static <K,
V1, V> BiCollector <K, V1, com.google.common.collect.ImmutableMap<K, V>> GuavaCollectors.toImmutableMap
(Collector<V1, ?, V> valueCollector) Returns aBiCollector
that collects the key-value pairs into anImmutableMap
usingvalueCollector
to collect values of identical keys into a final value of typeV
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableMultiset<K>> GuavaCollectors.toImmutableMultiset
(ToIntFunction<? super V> countFunction) Returns aBiCollector
that collects the key-value pairs into anImmutableMultiset
whose elements are the keys, with counts equal to the result of applyingcountFunction
to the values.static <K extends Comparable<K>,
V>
BiCollector<com.google.common.collect.Range<K>, V, com.google.common.collect.ImmutableRangeMap<K, V>> GuavaCollectors.toImmutableRangeMap()
Returns a BiCollector that takes input (disjoint) ranges and the corresponding values and builds anImmutableRangeMap
.static <K extends Comparable<K>,
V>
BiCollector<com.google.common.collect.Range<K>, V, com.google.common.collect.ImmutableRangeMap<K, V>> GuavaCollectors.toImmutableRangeMap
(BinaryOperator<V> merger) Returns a BiCollector that merges values mapped to overlapping ranges using themerger
function and builds anImmutableRangeMap
with disjoint ranges and the corresponding merged values.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableSetMultimap<K, V>> GuavaCollectors.toImmutableSetMultimap()
Returns aBiCollector
that collects the key-value pairs into anImmutableSetMultimap
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableSortedMap<K, V>> GuavaCollectors.toImmutableSortedMap
(Comparator<? super K> comparator) Returns aBiCollector
that collects the key-value pairs into anImmutableSortedMap
according tocomparator
.static <K,
V> BiCollector <K, V, com.google.common.collect.ImmutableSortedMap<K, V>> GuavaCollectors.toImmutableSortedMap
(Comparator<? super K> comparator, BinaryOperator<V> valueMerger) Returns aBiCollector
that collects the key-value pairs into anImmutableSortedMap
according tocomparator
, usingvalueMerger
to merge values of duplicate keys.static <R,
C, V> BiCollector <R, BiStream<? extends C, ? extends V>, com.google.common.collect.ImmutableTable<R, C, V>> GuavaCollectors.toImmutableTable()
Returns aBiCollector
that collects the key-value pairs into ancom.google.common.collect.ImmutableTable<R,
, where each input key (of typeC, V> R
) is mapped to a row in the table, and each input value is aBiStream<C, V>
whose keys (of typeC
) are mapped to columns in the table, and whose values (of typeV
) are mapped to the cell values.static <K,
V> BiCollector <K, V, Map<K, V>> BiCollectors.toMap()
Returns aBiCollector
that collects the key-value pairs into an immutableMap
.static <K,
V> BiCollector <K, V, Map<K, V>> BiCollectors.toMap
(BinaryOperator<V> valueMerger) Returns aBiCollector
that collects the key-value pairs into an immutableMap
usingvalueMerger
to merge values of duplicate keys.static <K,
V, M extends Map<K, V>>
BiCollector<K, V, M> static <K,
V1, V> BiCollector <K, V1, Map<K, V>> Returns aBiCollector
that collects the key-value pairs into an immutableMap
usingvalueCollector
to collect values of identical keys into a final value of typeV
.static <K,
V, M extends com.google.common.collect.Multimap<K, V>>
BiCollector<K, V, M> GuavaCollectors.toMultimap
(Supplier<M> multimapSupplier) Returns aBiCollector
that collects the key-value pairs into aMultimap
created withmultimapSupplier
.static <K extends Comparable<K>,
V, M extends com.google.common.collect.RangeMap<K, V>>
BiCollector<com.google.common.collect.Range<K>, V, M> GuavaCollectors.toRangeMap
(Supplier<? extends M> factory, BinaryOperator<V> merger) Returns a BiCollector that merges values mapped to overlapping ranges using themerger
function and builds a mutableRangeMap
of typeM
that's created byfactory
, and populated with disjoint ranges and the corresponding merged values.Modifier and TypeMethodDescriptionabstract <R> R
BiStream.collect
(BiCollector<? super K, ? super V, R> collector) Returns an object of typeR
that is the result of collecting the pairs in this stream usingcollector
.final <T,
R> R BiStream.collect
(BiCollector<? super K, ? super V, T> collector, Function<? super T, R> finisher) Equivalent tocollect(collectingAndThen(collector, finisher))
but helps to save syntactic noise.static <K,
V, A, B, R>
BiCollector<K, V, R> BiCollectors.collectingAndThen
(BiCollector<K, V, ? extends Both<? extends A, ? extends B>> collector, BiFunction<? super A, ? super B, ? extends R> finisher) static <K,
V, T, R>
BiCollector<K, V, R> BiCollectors.collectingAndThen
(BiCollector<K, V, T> upstream, Function<? super T, ? extends R> finisher) static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.flatMapping
(BiFunction<? super K, ? super V, ? extends BiStream<? extends K1, ? extends V1>> flattener, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first flattens the input pair usingflattener
and then collects the result pairs usingdownstream
collector.static <T,
K, V, R>
Collector<T, ?, R> MoreCollectors.flatMapping
(Function<? super T, ? extends BiStream<? extends K, ? extends V>> flattener, BiCollector<K, V, R> downstream) Similar but slightly different thanCollectors.flatMapping(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends U>>, java.util.stream.Collector<? super U, A, R>)
, returns aCollector
that first flattens the input stream of pairs (as opposed to single elements) and then collects the flattened pairs with thedownstream
BiCollector.MoreCollectors.flatteningMaps
(BiCollector<K, V, R> downstream) Returns aCollector
that flattens the inputMap
entries and collects them using thedownstream
BiCollector.final <G,
A, R> BiStream <G, R> BiStream.groupConsecutiveBy
(BiFunction<? super K, ? super V, ? extends G> classifier, BiCollector<? super K, ? super V, R> groupCollector) Returns aBiStream
consisting of consecutive groupings from this stream.final <R> Stream
<R> BiStream.groupConsecutiveIf
(BiStream.Partitioner<? super K, ? super V> sameGroup, BiCollector<? super K, ? super V, R> groupCollector) Returns a lazyStream
of the consecutive groups of values from this stream.static <K,
V, G, R>
BiCollector<K, V, BiStream<G, R>> BiCollectors.groupingBy
(BiFunction<? super K, ? super V, ? extends G> classifier, BiCollector<? super K, ? super V, R> groupCollector) Groups input entries byclassifier
and collects entries belonging to the same group usinggroupCollector
.static <A,
B, R> BiCollector <A, B, R> BiCollectors.inverse
(BiCollector<B, A, R> downstream) Returns a BiCollector that inverses the input pairs of(a, b)
into(b, a)
before passing it todownstream
collector.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(BiFunction<? super K, ? super V, ? extends Both<? extends K1, ? extends V1>> mapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair into another pair usingmapper
.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(BiFunction<? super K, ? super V, ? extends K1> keyMapper, BiFunction<? super K, ? super V, ? extends V1> valueMapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair usingkeyMapper
andvalueMapper
respectively, then collects the results usingdownstream
collector.static <K,
V, K1, V1, R>
BiCollector<K, V, R> BiCollectors.mapping
(Function<? super K, ? extends K1> keyMapper, Function<? super V, ? extends V1> valueMapper, BiCollector<K1, V1, R> downstream) Returns aBiCollector
that first maps the input pair usingkeyMapper
andvalueMapper
, then collects the results using thedownstream
collector.static <T,
A, B, R>
Collector<T, ?, R> MoreCollectors.mapping
(Function<? super T, ? extends Both<? extends A, ? extends B>> mapper, BiCollector<A, B, R> downstream) Analogous toCollectors.mapping()
, applies a mapping function to each input element before accumulation, except that themapper
function returns a pair of elements, which are then accumulated by a BiCollector.static <K,
V, R> BiCollector <K, V, Both<R, R>> BiCollectors.partitioningBy
(BiPredicate<? super K, ? super V> predicate, BiCollector<? super K, ? super V, ? extends R> downstream) Returns a BiCollector that partitions the incoming pairs into two groups: elements that matchpredicate
, and those that don't, and usedownstream
collector to collect the pairs.static <K,
V, T, F>
BiCollector<K, V, Both<T, F>> BiCollectors.partitioningBy
(BiPredicate<? super K, ? super V> predicate, BiCollector<? super K, ? super V, ? extends T> ifTrue, BiCollector<? super K, ? super V, ? extends F> ifFalse) Returns a BiCollector that partitions the incoming pairs into two groups: elements that matchpredicate
, and those that don't, and useifTrue
andifFalse
downstream collectors respectively to collect the pairs.