Interface BiCollector<K,V,R>
- Type Parameters:
K
- the key typeV
- the value typeR
- the result type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
BiCollector
collects "pairs of things", just as a Collector
collects
"things".
BiCollector
is usually passed to BiStream.collect(com.google.mu.util.stream.BiCollector<? super K, ? super V, R>)
. For example, to collect the
input pairs to a ConcurrentMap
:
ConcurrentMap<String, Integer> map = BiStream.of("a", 1).collect(Collectors::toConcurrentMap);
In addition to the common implementations provided by BiCollectors
,
many Collector
-returning factory methods can be directly "method referenced" as
BiCollector
if the method accepts two Function
parameters corresponding to "key" and
"value" respectively. For example: Collectors::toConcurrentMap
,
ImmutableSetMultimap::toImmutableSetMultimap
, Maps::toImmutableEnumMap
and
ImmutableBiMap::toImmutableBiMap
etc.
-
Method Summary
-
Method Details
-
collectorOf
Returns aCollector
such that the keys (as returned by thetoKey
function) and values (as returned by thetoValue
function) of the input elements are collected by thisBiCollector
.Conceptually
toImmutableMap(Employee::id, Employee::manager)
is equivalent toBiCollectors.toImmutableMap().collectorOf(Employee::id, Employee::manager)
.- Type Parameters:
E
- used to abstract away the underlying pair/entry type used byBiStream
.- Parameters:
toKey
- The function to read the key from the input entry. May be applied on the same input entry multiple times. Because input entries could be ephemeral likeMap.Entry
, applying the function on a previous input entry has undefined result.toValue
- The function to read the value from the input entry. May be applied on the same input entry multiple times. Because input entries could be ephemeral likeMap.Entry
, applying the function on a previous input entry has undefined result.- Since:
- 6.6
-