Uses of Class
com.google.mu.util.stream.BiStream
Package
Description
A few useful collections.
StringFormat, Substring, Optionals and more...
Parallelizer (parallel stream using Executor), Retryer.
Stream-based incremental graph algorithms.
BiStream, BiCollector, MoreStreams, MoreCollectors etc.
-
Uses of BiStream in com.google.mu.collect
-
Uses of BiStream in com.google.mu.util
Modifier and TypeMethodDescriptionSubstring.RepeatingPattern.alternationFrom
(String input) Returns the alternation of this pattern from theinput
string, with the matched substring alternated with the trailing substring before the next match.Substring.RepeatingPattern.splitKeyValuesAround
(Substring.Pattern keyValueSeparator, String input) Returns aBiStream
of key value pairs frominput
.Substring.RepeatingPattern.splitThenTrimKeyValuesAround
(Substring.Pattern keyValueSeparator, String input) Returns aBiStream
of key value pairs frominput
.BiOptional.stream()
Returns aBiStream
view of this BiOptional.Modifier and TypeMethodDescriptionStringFormat.Interpolator.interpolate
(List<String> fragments, BiStream<Substring.Match, Object> placeholders) Interpolates withfragments
of sizeN + 1
andplaceholders
of sizeN
. -
Uses of BiStream in com.google.mu.util.concurrent
Modifier and TypeMethodDescriptionParallelizer.inParallel
(Function<? super I, ? extends O> concurrentFunction) -
Uses of BiStream in com.google.mu.util.graph
Modifier and TypeMethodDescriptionShortestPath.stream()
Returns all nodes from the starting node along this path, with the cumulative distances from the starting node up to each node in the stream, respectively.Modifier and TypeMethodDescriptionstatic <N> Stream
<ShortestPath<N>> ShortestPath.shortestPathsFrom
(N startNode, Function<? super N, ? extends BiStream<? extends N, Double>> findSuccessors) Returns a lazy stream of shortest paths starting fromstartNode
. -
Uses of BiStream in com.google.mu.util.stream
Modifier and TypeMethodDescriptionReturns aBiStream
consisting of the pairs in this stream, followed by the pairs inother
.Returns aBiStream
consisting of the pairs in this stream, followed by the pair ofkey
andvalue
.static <K,
V> BiStream <K, V> BiStream.biStream
(Collection<K> keys, Function<? super K, ? extends V> toValue) Returns aBiStream
of mappings betweenkeys
and the corresponding return values of thetoValue
function.static <T> BiStream
<T, T> BiStream.biStream
(Collection<T> elements) Short-hand forfrom(elements, identity(), identity())
.static <K,
V> BiStream <K, V> BiStream.biStream
(Function<? super V, ? extends K> toKey, Collection<V> values) Returns aBiStream
of mappings between the key returned by thetoKey
function (when applied to each element ofvalues
), and the element itself.static <K,
V> BiStream <K, V> Returns aBiStream
of mappings between the key returned by thetoKey
function (when applied to each element ofvalues
), and the element itself.static <K,
V> BiStream <K, V> Returns aBiStream
of mappings betweenkeys
and the corresponding return values of thetoValue
function.static <T> BiStream
<T, T> Short-hand forfrom(elements, identity(), identity())
.BiStream.Builder.build()
static <K,
V> BiStream <K, V> BiStream.concat
(BiStream<? extends K, ? extends V> s1, BiStream<? extends K, ? extends V> s2, BiStream<? extends K, ? extends V>... rest) Returns aBiStream
of the entries froms1
,s2
thenrest
in encounter order.static <K,
V> BiStream <K, V> BiStream.concat
(Map<? extends K, ? extends V> m1, Map<? extends K, ? extends V> m2, Map<? extends K, ? extends V>... rest) Returns aBiStream
of the entries fromm1
,m2
thenrest
in encounter order.static <K,
V> BiStream <K, V> Returns aBiStream
of pairs frombiStreams
concatenated in encounter order.BiStream.distinct()
Returns aBiStream
consisting of only the distinct pairs (according toObject.equals(Object)
for both key and value).static <K,
V> BiStream <K, V> BiStream.empty()
Returns an emptyBiStream
.BiStream.filter
(BiPredicate<? super K, ? super V> predicate) Filter this stream to only pairs matchingpredicate
.BiStream.filterKeys
(Predicate<? super K> predicate) Filter this stream to only pairs whose key matchespredicate
.BiStream.filterValues
(Predicate<? super V> predicate) Filter this stream to only pairs whose value matchespredicate
.final <K2,
V2> BiStream <K2, V2> BiStream.flatMap
(BiFunction<? super K, ? super V, ? extends BiStream<? extends K2, ? extends V2>> mapper) Maps each pair in this stream to zero or more pairs in anotherBiStream
.BiStream.flatMapKeys
(BiFunction<? super K, ? super V, ? extends Stream<? extends K2>> keyMapper) Maps each key to zero or more keys of typeK2
.BiStream.flatMapKeys
(Function<? super K, ? extends Stream<? extends K2>> keyMapper) Maps each key to zero or more keys of typeK2
.BiStream.flatMapValues
(BiFunction<? super K, ? super V, ? extends Stream<? extends V2>> valueMapper) Maps each value to zero or more values of typeV2
.BiStream.flatMapValues
(Function<? super V, ? extends Stream<? extends V2>> valueMapper) Maps each value to zero or more values of typeV2
.static <K,
V> BiStream <K, V> BiStream.from
(Collection<? extends Map.Entry<? extends K, ? extends V>> entries) Returns aBiStream
of the key value pairs fromentries
.static <T,
K, V> BiStream <K, V> BiStream.from
(Collection<T> elements, Function<? super T, ? extends K> toKey, Function<? super T, ? extends V> toValue) Deprecated.static <K,
V> BiStream <K, V> Returns aBiStream
of the entries inmap
.static <K,
V> BiStream <K, V> Returns aBiStream
of the pairs fromstream
.static <T,
K, V> BiStream <K, V> BiStream.from
(Stream<T> stream, Function<? super T, ? extends K> toKey, Function<? super T, ? extends V> toValue) Deprecated.UsebiStream(User::id, users)
to createBiStream<UserId, User>
, or, usebiStream(users, User::getAccount)
to createBiStream<User, Account>
.BiStream.fromEntries
(Stream<E> entryStream) 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.BiStream.groupConsecutiveBy
(Function<? super K, ? extends G> classifier, BinaryOperator<V> groupReducer) Returns a lazyBiStream
of the consecutive groups of pairs from this stream.final <G,
A, R> BiStream <G, R> BiStream.groupConsecutiveBy
(Function<? super K, ? extends G> classifier, Collector<? super V, A, ? extends R> groupCollector) Returns aBiStream
consisting of consecutive groupings from this stream.BiStream.inverse()
Returns aBiStream
where each pair is a pair from this stream with the key and value swapped.BiIteration.iterate()
Starts iteration over theyielded
pairs.BiStream.limit
(int maxSize) Returns aBiStream
consisting of the only the firstmaxSize
pairs of this stream.final <K2,
V2> BiStream <K2, V2> BiStream.map
(BiFunction<? super K, ? super V, ? extends Both<? extends K2, ? extends V2>> mapper) Returns aBiStream
consisting of the result pairs of applyingmapper
to the pairs in thisBiStream
.<K2,
V2> BiStream <K2, V2> BiStream.map
(BiFunction<? super K, ? super V, ? extends K2> keyMapper, BiFunction<? super K, ? super V, ? extends V2> valueMapper) Returns aBiStream
consisting of the results of applyingkeyMapper
andvalueMapper
to the pairs in thisBiStream
.final <K2,
V2> BiStream <K2, V2> BiStream.mapIfPresent
(BiFunction<? super K, ? super V, ? extends BiOptional<? extends K2, ? extends V2>> mapper) Returns aBiStream
consisting of the results of applyingmapper
function to the pairs in thisBiStream
.BiStream.mapKeys
(BiFunction<? super K, ? super V, ? extends K2> keyMapper) Returns aBiStream
of pairs whose keys are the result of applyingkeyMapper
to the key of each pair in thisBiStream
, and whose values are unchanged.Maps each key to another key of typeK2
.BiStream.mapKeysIfPresent
(BiFunction<? super K, ? super V, ? extends Optional<? extends K2>> keyMapper) Returns aBiStream
of pairs whose keys are the result of applyingkeyMapper
to each pair in thisBiStream
, and whose values are unchanged.BiStream.mapKeysIfPresent
(Function<? super K, ? extends Optional<? extends K2>> keyMapper) Returns aBiStream
of pairs whose keys are the result of applyingkeyMapper
to the key of each pair in thisBiStream
, and whose values are unchanged.BiStream.mapKeysIfPresent
(Map<? super K, ? extends K2> keyMapping) GivenkeyMapping
that maps the keys of typeK
to elements of typeK2
, returns aBiStream
of type<K2, V>
.BiStream.mapValues
(BiFunction<? super K, ? super V, ? extends V2> valueMapper) Maps each value to another value of typeV2
.Maps each value to another value of typeV2
.BiStream.mapValuesIfPresent
(BiFunction<? super K, ? super V, ? extends Optional<? extends V2>> valueMapper) Returns aBiStream
of pairs whose values are the result of applyingvalueMapper
to each pair in thisBiStream
, and whose keys are unchanged.BiStream.mapValuesIfPresent
(Function<? super V, ? extends Optional<? extends V2>> valueMapper) Returns aBiStream
of pairs whose values are the result of applyingvalueMapper
to the value of each pair in thisBiStream
, and whose keys are unchanged.BiStream.mapValuesIfPresent
(Map<? super V, ? extends V2> valueMapping) GivenvalueMapping
that maps values of typeV
to result values of typeV2
, returns aBiStream
of type<K, V2>
.static <K,
V> BiStream <K, V> BiStream.of
(K key, V value) Returns aBiStream
of a single pair containingkey
andvalue
.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2) Returns aBiStream
of two pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3) Returns aBiStream
of three pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Returns aBiStream
of 4 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Returns aBiStream
of 5 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Returns aBiStream
of 6 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Returns aBiStream
of 7 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Returns aBiStream
of 8 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) Returns aBiStream
of 9 pairs, containing the supplied keys and values.static <K,
V> BiStream <K, V> BiStream.of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) Returns aBiStream
of 10 pairs, containing the supplied keys and values.BiStream.peek
(BiConsumer<? super K, ? super V> action) Returns aBiStream
consisting of the pairs of this stream, additionally invokingaction
on each pair as pairs are consumed from the resulting stream.static <I,
O> BiStream <I, O> BiStream.repeat
(Function<? super I, ? extends O> work, I initial, BiFunction<? super I, ? super O, ? extends Optional<? extends I>> increment) Returns a stream of the inputs and outputs from repeated applications of thework
function.MoreStreams.runLengthEncode
(Stream<T> stream, BiPredicate<? super T, ? super T> sameGroup) Groups consecutive items instream
using thesameGroup
predicate, along with the group's run length (number of items).BiStream.skip
(int n) Returns aBiStream
consisting of the remaining pairs from this stream, after discarding the firstn
pairs.BiStream.skipIf
(BiPredicate<? super K, ? super V> predicate) Filter this stream to exclude pairs matchingpredicate
.BiStream.skipKeysIf
(Predicate<? super K> predicate) Filter this stream to exclude pairs whose key matchespredicate
.BiStream.skipValuesIf
(Predicate<? super V> predicate) Filter this stream to exclude pairs whose value matchespredicate
.BiStream.sorted
(Comparator<? super K> byKey, Comparator<? super V> byValue) Returns aBiStream
consisting of the pairs in this stream, in the order produced by applying thebyKey
comparator on the keys of each pair, and then thebyValue
comparator on the values of pairs with equal keys.BiStream.sortedBy
(BiFunction<? super K, ? super V, T> sortKeyFunction, Comparator<? super T> comparator) Returns aBiStream
consisting of the pairs in this stream, in the order produced by applyingcomparator
on the result of applying thesortKeyFunction
.BiStream.sortedByKeys
(Comparator<? super K> comparator) Returns aBiStream
consisting of the pairs in this stream, in the order produced by applyingcomparator
on the keys of each pair.BiStream.sortedByValues
(Comparator<? super V> comparator) Returns aBiStream
consisting of the pairs in this stream, in the order produced by applyingcomparator
on the values of each pair.BiCollection.stream()
Deprecated.Streams over thisBiCollection
.static <L,
R> BiStream <L, R> BiStream.zip
(Collection<L> left, Collection<R> right) Returns aBiStream
in which the first element inleft
is paired with the first element inright
; the second paired with the corresponding second and the third with the corresponding third etc.static <L,
R> BiStream <L, R> Returns aBiStream
in which the first element inleft
is paired with the first element inright
; the second paired with the corresponding second and the third with the corresponding third etc.Modifier and TypeMethodDescriptionBiStream.concatenating
(Function<? super T, ? extends BiStream<? extends K, ? extends V>> toBiStream) Returns aCollector
that concatenatesBiStream
objects derived from the input elements using the giventoBiStream
function.BiStream.crossJoining
(Stream<R> right) Returns aCollector
that will pair each input element with each element fromright
into a newBiStream
.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 <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
.BiStream.groupingBy
(Function<? super T, ? extends K> classifier) Returns aCollector
that groups the input elements byclassifier
and collects the values mapping to the same key into aList
.BiStream.groupingBy
(Function<? super T, ? extends K> classifier, Function<? super T, ? extends V> mapper, BinaryOperator<V> reducer) Returns aCollector
that groups the input elements byclassifier
and reduces the values mapping to the same key usingmapper
thenreducer
.BiStream.groupingBy
(Function<? super T, ? extends K> classifier, Collector<? super T, ?, V> valueCollector) Returns aCollector
that groups the input elements byclassifier
and collects the values mapping to the same key usingvalueCollector
.BiStream.groupingBy
(Function<? super V, ? extends K> classifier, BinaryOperator<V> reducer) Returns aCollector
that groups the input elements byclassifier
and reduces the values mapping to the same key usingreducer
.BiStream.groupingByEach
(Function<? super T, ? extends Stream<? extends K>> keysFunction, Function<? super T, ? extends V> valueFunction, BinaryOperator<V> groupReducer) Returns aCollector
grouping input elements by each of the multiple keys returned by thekeysFunction
.BiStream.groupingByEach
(Function<? super T, ? extends Stream<? extends K>> keysFunction, Function<? super T, ? extends V> valueFunction, Collector<V, ?, G> groupCollector) Returns aCollector
grouping input elements by each of the multiple keys returned by thekeysFunction
.BiStream.groupingByEach
(Function<? super T, ? extends Stream<? extends K>> keysFunction, Collector<T, ?, V> groupCollector) Returns aCollector
grouping input elements by each of the multiple keys returned by thekeysFunction
.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> 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.BiStream.toAdjacentPairs()
Returns aCollector
that accumulates every neighboring pair of elements into a newBiStream
.BiStream.toBiStream()
Returns aCollector
that copies each input element as a pair of itself into an equivalentBiStream
.BiStream.toBiStream
(Function<? super E, ? extends Both<? extends K, ? extends V>> toPair) Returns aCollector
that splits each input element as a pair and collects them into aBiStream
.BiStream.toBiStream
(Function<? super E, ? extends K> toKey, Function<? super E, ? extends V> toValue) Returns aCollector
that splits each input element as a pair and collects them into aBiStream
.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 <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.Modifier and TypeMethodDescriptionReturns aBiStream
consisting of the pairs in this stream, followed by the pairs inother
.static <K,
V> BiStream <K, V> BiStream.concat
(BiStream<? extends K, ? extends V> s1, BiStream<? extends K, ? extends V> s2, BiStream<? extends K, ? extends V>... rest) Returns aBiStream
of the entries froms1
,s2
thenrest
in encounter order.Modifier and TypeMethodDescriptionstatic <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> BiStream <K, V> Returns aBiStream
of pairs frombiStreams
concatenated in encounter order.BiStream.concatenating
(Function<? super T, ? extends BiStream<? extends K, ? extends V>> toBiStream) Returns aCollector
that concatenatesBiStream
objects derived from the input elements using the giventoBiStream
function.final <K2,
V2> BiStream <K2, V2> BiStream.flatMap
(BiFunction<? super K, ? super V, ? extends BiStream<? extends K2, ? extends V2>> mapper) Maps each pair in this stream to zero or more pairs in anotherBiStream
.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.
biStream(User::id, users)
to createBiStream<UserId, User>
, or, usebiStream(users, User::getAccount)
to createBiStream<User, Account>
.