public abstract class RemoteCollectors extends Object
RemoteCollectors that can be executed in
parallel in a distributed environment.RemoteCollector,
Collectors| Constructor and Description |
|---|
RemoteCollectors() |
| Modifier and Type | Method and Description |
|---|---|
static <T,U> RemoteCollector<T,?,Double> |
averagingDouble(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the arithmetic mean of a
double-valued function applied to the input elements. |
static <T,U> RemoteCollector<T,?,Double> |
averagingInt(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the arithmetic mean of an
integer-valued function applied to the input elements. |
static <T,U> RemoteCollector<T,?,Double> |
averagingLong(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the arithmetic mean of a
long-valued function applied to the input elements. |
static <T,A,R,RR> RemoteCollector<T,A,RR> |
collectingAndThen(RemoteCollector<T,A,R> downstream,
Remote.Function<R,RR> finisher)
Adapts a
Collector to perform an additional finishing
transformation. |
static <T> RemoteCollector<T,?,Long> |
counting()
Returns a
Collector accepting elements of type T that
counts the number of input elements. |
static <T,U,K> RemoteCollector<T,?,Map<K,List<T>>> |
groupingBy(ValueExtractor<? super U,? extends K> classifier)
Returns a
Collector implementing a "group by" operation on input
elements of type T, grouping elements according to a
classification function, and returning the results in a Map. |
static <T,U,K,D,A,M extends Map<K,D>> |
groupingBy(ValueExtractor<? super U,? extends K> extractor,
Remote.Supplier<M> mapFactory,
RemoteCollector<? super T,A,D> downstream)
Returns a
Collector implementing a cascaded "group by" operation
on input elements of type T, grouping elements according to a
classification function, and then performing a reduction operation on the
values associated with a given key using the specified downstream Collector. |
static <T,U,K,A,D> |
groupingBy(ValueExtractor<? super U,? extends K> classifier,
RemoteCollector<? super T,A,D> downstream)
Returns a
Collector implementing a cascaded "group by" operation
on input elements of type T, grouping elements according to a
classification function, and then performing a reduction operation on the
values associated with a given key using the specified downstream Collector. |
static <T,U,A,R> RemoteCollector<T,A,R> |
mapping(Remote.Function<? super T,? extends U> mapper,
RemoteCollector<? super U,A,R> downstream)
Adapts a
Collector accepting elements of type U to one
accepting elements of type T by applying a mapping function to
each input element before accumulation. |
static <T> RemoteCollector<T,?,Optional<T>> |
maxBy(Remote.Comparator<? super T> comparator)
Returns a
Collector that produces the maximal element according
to a given Comparator, described as an Optional<T>. |
static <T> RemoteCollector<T,?,Optional<T>> |
minBy(Remote.Comparator<? super T> comparator)
Returns a
Collector that produces the minimal element according
to a given Comparator, described as an Optional<T>. |
static <T> RemoteCollector<T,?,Optional<T>> |
reducing(Remote.BinaryOperator<T> op)
Returns a
Collector which performs a reduction of its input
elements under a specified BinaryOperator. |
static <T> RemoteCollector<T,SimpleHolder<T>,T> |
reducing(T identity,
Remote.BinaryOperator<T> op)
Returns a
Collector which performs a reduction of its input
elements under a specified BinaryOperator using the provided
identity. |
static <T,U> RemoteCollector<T,?,U> |
reducing(U identity,
Remote.BiFunction<? super U,? super T,? extends U> mapper,
Remote.BinaryOperator<U> op)
Returns a
Collector which performs a reduction of its input
elements under a specified mapping function and BinaryOperator. |
static <T,U> RemoteCollector<T,?,U> |
reducing(U identity,
Remote.Function<? super T,? extends U> mapper,
Remote.BinaryOperator<U> op)
Returns a
Collector which performs a reduction of its input
elements under a specified mapping function and BinaryOperator. |
static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.DoubleSummaryStatistics> |
summarizingDouble(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector which applies an double-producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.IntSummaryStatistics> |
summarizingInt(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector which applies an int-producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.LongSummaryStatistics> |
summarizingLong(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector which applies an long-producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T,U> RemoteCollector<T,?,Double> |
summingDouble(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the sum of a double-valued
function applied to the input elements. |
static <T,U> RemoteCollector<T,?,Integer> |
summingInt(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the sum of a integer-valued
function applied to the input elements. |
static <T,U> RemoteCollector<T,?,Long> |
summingLong(ValueExtractor<? super U,? extends Number> extractor)
Returns a
Collector that produces the sum of a long-valued
function applied to the input elements. |
static <T,C extends Collection<T>> |
toCollection(Remote.Supplier<C> supplier)
Returns a
Collector that accumulates the input elements into a
new Collection, in encounter order. |
static <T> RemoteCollector<T,?,List<T>> |
toList()
Returns a
Collector that accumulates the input elements into a
new List. |
static <T,U1,U2,K,V> |
toMap(ValueExtractor<? super U1,? extends K> keyMapper,
ValueExtractor<? super U2,? extends V> valueMapper)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T,U1,U2,K,V> |
toMap(ValueExtractor<? super U1,? extends K> keyMapper,
ValueExtractor<? super U2,? extends V> valueMapper,
Remote.BinaryOperator<V> mergeFunction)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T,U1,U2,K,V,M extends Map<K,V>> |
toMap(ValueExtractor<? super U1,? extends K> keyExtractor,
ValueExtractor<? super U2,? extends V> valueExtractor,
Remote.BinaryOperator<V> mergeFunction,
Remote.Supplier<M> mapSupplier)
Returns a
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements. |
static <T> RemoteCollector<T,?,Set<T>> |
toSet()
Returns a
Collector that accumulates the input elements into a
new Set. |
static <T> RemoteCollector<T,?,Collection<T>> |
toSortedBag()
Returns a
Collector that accumulates the input elements into a
new SortedBag. |
static <T> RemoteCollector<T,?,Collection<T>> |
toSortedBag(Comparator<? super T> comparator)
Returns a
Collector that accumulates the input elements into a
new SortedBag. |
static <T> RemoteCollector<T,?,Collection<T>> |
toSortedBag(Remote.Comparator<? super T> comparator)
Returns a
Collector that accumulates the input elements into a
new SortedBag. |
static <T> RemoteCollector<T,?,SortedSet<T>> |
toSortedSet()
Returns a
Collector that accumulates the input elements into a
new SortedSet. |
static <T> RemoteCollector<T,?,SortedSet<T>> |
toSortedSet(Comparator<? super T> comparator)
Returns a
Collector that accumulates the input elements into a
new SortedSet. |
static <T> RemoteCollector<T,?,SortedSet<T>> |
toSortedSet(Remote.Comparator<? super T> comparator)
Returns a
Collector that accumulates the input elements into a
new SortedSet. |
public static <T,C extends Collection<T>> RemoteCollector<T,?,C> toCollection(Remote.Supplier<C> supplier)
Collector that accumulates the input elements into a
new Collection, in encounter order. The Collection is
created by the provided factory.T - the type of the input elementsC - the type of the resulting Collectionsupplier - a Supplier which returns a new, empty
Collection of the appropriate typeCollector which collects all the input elements into a
Collection, in encounter orderpublic static <T> RemoteCollector<T,?,List<T>> toList()
Collector that accumulates the input elements into a
new List. There are no guarantees on the type, mutability,
serializability, or thread-safety of the List returned; if more
control over the returned List is required, use toCollection(Remote.Supplier).T - the type of the input elementsCollector which collects all the input elements into a
List, in encounter orderpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag()
Collector that accumulates the input elements into a
new SortedBag.T - the type of the input elementsCollector which collects all the input elements into a
List, in encounter orderpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag(Comparator<? super T> comparator)
Collector that accumulates the input elements into a
new SortedBag.T - the type of the input elementscomparator - a comparator for type TCollector which collects all the input elements into a
List, in encounter orderpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag(Remote.Comparator<? super T> comparator)
Collector that accumulates the input elements into a
new SortedBag.T - the type of the input elementscomparator - a comparator for type TCollector which collects all the input elements into a
List, in encounter orderpublic static <T> RemoteCollector<T,?,Set<T>> toSet()
Collector that accumulates the input elements into a
new Set. There are no guarantees on the type, mutability,
serializability, or thread-safety of the Set returned; if more
control over the returned Set is required, use toCollection(Remote.Supplier).
This is an unordered
Collector.
T - the type of the input elementsCollector which collects all the input elements into a
Setpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet()
Collector that accumulates the input elements into a
new SortedSet. There are no guarantees on the type, mutability,
serializability, or thread-safety of the SortedSet returned;
if more control over the returned SortedSet is required, use
toCollection(Remote.Supplier).
This is an unordered
Collector.
T - the type of the input elementsCollector which collects all the input elements into a
Setpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet(Comparator<? super T> comparator)
Collector that accumulates the input elements into a
new SortedSet. There are no guarantees on the type, mutability,
serializability, or thread-safety of the SortedSet returned;
if more control over the returned SortedSet is required, use
toCollection(Remote.Supplier).
This is an unordered
Collector.
T - the type of the input elementscomparator - a comparator for type TCollector which collects all the input elements into a
Setpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet(Remote.Comparator<? super T> comparator)
Collector that accumulates the input elements into a
new SortedSet. There are no guarantees on the type, mutability,
serializability, or thread-safety of the SortedSet returned;
if more control over the returned SortedSet is required, use
toCollection(Remote.Supplier).
This is an unordered
Collector.
T - the type of the input elementscomparator - a comparator for type TCollector which collects all the input elements into a
Setpublic static <T,U,A,R> RemoteCollector<T,A,R> mapping(Remote.Function<? super T,? extends U> mapper, RemoteCollector<? super U,A,R> downstream)
Collector accepting elements of type U to one
accepting elements of type T by applying a mapping function to
each input element before accumulation.T - the type of the input elementsU - type of elements accepted by downstream collectorA - intermediate accumulation type of the downstream
collectorR - result type of collectormapper - a function to be applied to the input elementsdownstream - a collector which will accept mapped valuesmapping() collectors are most useful when used in a
multi-level reduction, such as downstream of a groupingBy or
partitioningBy. For example, given a stream of Person,
to accumulate the set of last names in each city:
Map<City, Set<String>> lastNamesByCity
= people.stream().collect(groupingBy(Person::getCity,
mapping(Person::getLastName,
toSet())));
public static <T,A,R,RR> RemoteCollector<T,A,RR> collectingAndThen(RemoteCollector<T,A,R> downstream, Remote.Function<R,RR> finisher)
Collector to perform an additional finishing
transformation. For example, one could adapt the toList()
collector to always produce an immutable list with:
List<String> people
= people.stream().collect(collectingAndThen(toList(),
Collections::unmodifiableList));
T - the type of the input elementsA - intermediate accumulation type of the downstream
collectorR - result type of the downstream collectorRR - result type of the resulting collectordownstream - a collectorfinisher - a function to be applied to the final result of the
downstream collectorpublic static <T> RemoteCollector<T,?,Long> counting()
Collector accepting elements of type T that
counts the number of input elements. If no elements are present, the
result is 0.T - the type of the input elementsCollector that counts the input elements
reducing(0L, e -> 1L, Long::sum)
public static <T> RemoteCollector<T,?,Optional<T>> minBy(Remote.Comparator<? super T> comparator)
Collector that produces the minimal element according
to a given Comparator, described as an Optional<T>.T - the type of the input elementscomparator - a Comparator for comparing elementsCollector that produces the minimal value
reducing(Remote.BinaryOperator.minBy(comparator))
public static <T> RemoteCollector<T,?,Optional<T>> maxBy(Remote.Comparator<? super T> comparator)
Collector that produces the maximal element according
to a given Comparator, described as an Optional<T>.T - the type of the input elementscomparator - a Comparator for comparing elementsCollector that produces the maximal value
reducing(BinaryOperator.maxBy(comparator))
public static <T,U> RemoteCollector<T,?,Integer> summingInt(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the sum of a integer-valued
function applied to the input elements. If no elements are present, the
result is 0.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be summedCollector that produces the sum of a derived propertypublic static <T,U> RemoteCollector<T,?,Long> summingLong(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the sum of a long-valued
function applied to the input elements. If no elements are present, the
result is 0.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be summedCollector that produces the sum of a derived propertypublic static <T,U> RemoteCollector<T,?,Double> summingDouble(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the sum of a double-valued
function applied to the input elements. If no elements are present, the
result is 0.
The sum returned can vary depending upon the order in which values are
recorded, due to accumulated rounding error in addition of values of
differing magnitudes. Values sorted by increasing absolute magnitude tend
to yield more accurate results. If any recorded value is a NaN
or the sum is at any point a NaN then the sum will be NaN.
T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be summedCollector that produces the sum of a derived propertypublic static <T,U> RemoteCollector<T,?,Double> averagingInt(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the arithmetic mean of an
integer-valued function applied to the input elements. If no elements
are present, the result is 0.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be summedCollector that produces the sum of a derived propertypublic static <T,U> RemoteCollector<T,?,Double> averagingLong(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the arithmetic mean of a
long-valued function applied to the input elements. If no elements are
present, the result is 0.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be averagedCollector that produces the average of a derived propertypublic static <T,U> RemoteCollector<T,?,Double> averagingDouble(ValueExtractor<? super U,? extends Number> extractor)
Collector that produces the arithmetic mean of a
double-valued function applied to the input elements. If no elements are
present, the result is 0.
The average returned can vary depending upon the order in which values
are recorded, due to accumulated rounding error in addition of values of
differing magnitudes. Values sorted by increasing absolute magnitude tend
to yield more accurate results. If any recorded value is a NaN
or the sum is at any point a NaN then the average will be NaN.
T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a function extracting the property to be summedCollector that produces the sum of a derived propertydouble format can represent all consecutive
integers in the range -253 to 253. If the pipeline
has more than 253 values, the divisor in the average
computation will saturate at 253, leading to additional
numerical errors.public static <T> RemoteCollector<T,SimpleHolder<T>,T> reducing(T identity, Remote.BinaryOperator<T> op)
Collector which performs a reduction of its input
elements under a specified BinaryOperator using the provided
identity.T - element type for the input and output of the reductionidentity - the identity value for the reduction (also, the value
that is returned when there are no input elements)op - a BinaryOperator<T> used to reduce the input
elementsCollector which implements the reduction operationreducing(Remote.BinaryOperator),
reducing(Object, Remote.Function, Remote.BinaryOperator)reducing() collectors are most useful when used in a
multi-level reduction, downstream of groupingBy or partitioningBy. To perform a simple reduction on a stream, use RemoteStream.reduce(Object, BinaryOperator)} instead.public static <T> RemoteCollector<T,?,Optional<T>> reducing(Remote.BinaryOperator<T> op)
Collector which performs a reduction of its input
elements under a specified BinaryOperator. The result is
described as an Optional<T>.T - element type for the input and output of the reductionop - a BinaryOperator<T> used to reduce the input elementsCollector which implements the reduction operationreducing(Object, Remote.BinaryOperator),
reducing(Object, Remote.Function, Remote.BinaryOperator)reducing() collectors are most useful when used in a
multi-level reduction, downstream of groupingBy or partitioningBy. To perform a simple reduction on a stream, use RemoteStream.reduce(BinaryOperator) instead.
For example, given a stream of Person, to calculate tallest
person in each city:
Comparator<Person> byHeight = Comparator.comparing(Person::getHeight);
Map<City, Person> tallestByCity
= people.stream().collect(groupingBy(Person::getCity,
reducing(BinaryOperator.maxBy(byHeight))));
public static <T,U> RemoteCollector<T,?,U> reducing(U identity, Remote.Function<? super T,? extends U> mapper, Remote.BinaryOperator<U> op)
Collector which performs a reduction of its input
elements under a specified mapping function and BinaryOperator.
This is a generalization of reducing(Object, Remote.BinaryOperator)
which allows a transformation of the elements before reduction.T - the type of the input elementsU - the type of the mapped valuesidentity - the identity value for the reduction (also, the value
that is returned when there are no input elements)mapper - a mapping function to apply to each input valueop - a BinaryOperator<U> used to reduce the mapped
valuesCollector implementing the map-reduce operationreducing(Object, Remote.BinaryOperator),
reducing(Remote.BinaryOperator)reducing() collectors are most useful when used in a
multi-level reduction, downstream of groupingBy or partitioningBy. To perform a simple map-reduce on a stream, use RemoteStream.map(Function) and RemoteStream.reduce(Object, BinaryOperator)
instead.
For example, given a stream of Person, to calculate the
longest last name of residents in each city:
Comparator<String> byLength = Comparator.comparing(String::length);
Map<City, String> longestLastNameByCity
= people.stream().collect(groupingBy(Person::getCity,
reducing(Person::getLastName,
BinaryOperator.maxBy(byLength))));
public static <T,U> RemoteCollector<T,?,U> reducing(U identity, Remote.BiFunction<? super U,? super T,? extends U> mapper, Remote.BinaryOperator<U> op)
Collector which performs a reduction of its input
elements under a specified mapping function and BinaryOperator.
This is a generalization of reducing(Object, Remote.BinaryOperator)
which allows a transformation of the elements before reduction.T - the type of the input elementsU - the type of the mapped valuesidentity - the identity value for the reduction (also, the value
that is returned when there are no input elements)mapper - a mapping function to apply to each input valueop - a BinaryOperator<U> used to reduce the mapped
valuesCollector implementing the map-reduce operationreducing(Object, Remote.BinaryOperator),
reducing(Remote.BinaryOperator)reducing() collectors are most useful when used in a
multi-level reduction, downstream of groupingBy or partitioningBy. To perform a simple map-reduce on a stream, use RemoteStream.map(Function) and RemoteStream.reduce(Object, BinaryOperator)
instead.
For example, given a stream of Person, to calculate the
longest last name of residents in each city:
Comparator<String> byLength = Comparator.comparing(String::length);
Map<City, String> longestLastNameByCity
= people.stream().collect(groupingBy(Person::getCity,
reducing(Person::getLastName,
BinaryOperator.maxBy(byLength))));
public static <T,U,K> RemoteCollector<T,?,Map<K,List<T>>> groupingBy(ValueExtractor<? super U,? extends K> classifier)
Collector implementing a "group by" operation on input
elements of type T, grouping elements according to a
classification function, and returning the results in a Map.
The classification function maps elements to some key type K.
The collector produces a Map<K, List<T>> whose keys are the
values resulting from applying the classification function to the input
elements, and whose corresponding values are Lists containing the
input elements which map to the associated key under the classification
function.
There are no guarantees on the type, mutability, serializability, or
thread-safety of the Map or List objects returned.
T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.EntryK - the type of the keysclassifier - the classifier function mapping input elements to keysCollector implementing the group-by operationgroupingBy(ValueExtractor, RemoteCollector),
groupingBy(ValueExtractor, Remote.Supplier, RemoteCollector)
groupingBy(classifier, toList());
public static <T,U,K,A,D> RemoteCollector<T,?,Map<K,D>> groupingBy(ValueExtractor<? super U,? extends K> classifier, RemoteCollector<? super T,A,D> downstream)
Collector implementing a cascaded "group by" operation
on input elements of type T, grouping elements according to a
classification function, and then performing a reduction operation on the
values associated with a given key using the specified downstream Collector.
The classification function maps elements to some key type K.
The downstream collector operates on elements of type T and
produces a result of type D. The resulting collector produces a
Map<K, D>.
There are no guarantees on the type, mutability, serializability, or
thread-safety of the Map returned.
For example, to compute the set of last names of people in each city:
Map<City, Set<String>> namesByCity
= people.stream().collect(groupingBy(Person::getCity,
mapping(Person::getLastName,
toSet())));
T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.EntryK - the type of the keysA - the intermediate accumulation type of the downstream
collectorD - the result type of the downstream reductionclassifier - a classifier function mapping input elements to keysdownstream - a Collector implementing the downstream
reductionCollector implementing the cascaded group-by operationgroupingBy(ValueExtractor),
groupingBy(ValueExtractor, Remote.Supplier, RemoteCollector)public static <T,U,K,D,A,M extends Map<K,D>> RemoteCollector<T,?,M> groupingBy(ValueExtractor<? super U,? extends K> extractor, Remote.Supplier<M> mapFactory, RemoteCollector<? super T,A,D> downstream)
Collector implementing a cascaded "group by" operation
on input elements of type T, grouping elements according to a
classification function, and then performing a reduction operation on the
values associated with a given key using the specified downstream Collector. The Map produced by the Collector is created with
the supplied factory function.
The classification function maps elements to some key type K.
The downstream collector operates on elements of type T and
produces a result of type D. The resulting collector produces a
Map<K, D>.
For example, to compute the set of last names of people in each city, where the city names are sorted:
Map<City, Set<String>> namesByCity
= people.stream().collect(groupingBy(Person::getCity,
TreeMap::new,
mapping(Person::getLastName,
toSet())));
T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.EntryK - the type of the keysA - the intermediate accumulation type of the downstream
collectorD - the result type of the downstream reductionM - the type of the resulting Mapextractor - an extractor function mapping input elements to keysdownstream - a Collector implementing the downstream
reductionmapFactory - a function which, when called, produces a new empty
Map of the desired typeCollector implementing the cascaded group-by operationgroupingBy(ValueExtractor, RemoteCollector),
groupingBy(ValueExtractor)public static <T,U1,U2,K,V> RemoteCollector<T,?,Map<K,V>> toMap(ValueExtractor<? super U1,? extends K> keyMapper, ValueExtractor<? super U2,? extends V> valueMapper)
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to Object.equals(Object)), an IllegalStateException is thrown when
the collection operation is performed. If the mapped keys may have
duplicates, use toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator)
instead.
T - the type of the stream elementsU1 - the type of the objects to extract keys from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryU2 - the type of the objects to extract values from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryK - the output type of the key mapping functionV - the output type of the value mapping functionkeyMapper - a mapping function to produce keysvalueMapper - a mapping function to produce valuesCollector which collects elements into a Map
whose keys and values are the result of applying mapping functions to the
input elementstoMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator),
toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator, Remote.Supplier)Function.identity() may be helpful. For example, the
following produces a Map mapping students to their grade point
average:
Map<Student, Double> studentToGPA
students.stream().collect(toMap(Functions.identity(),
student ->
computeGPA(student)));
And the following produces a Map mapping a unique identifier to
students:
Map<String, Student> studentIdToStudent
students.stream().collect(toMap(Student::getId,
Functions.identity());
public static <T,U1,U2,K,V> RemoteCollector<T,?,Map<K,V>> toMap(ValueExtractor<? super U1,? extends K> keyMapper, ValueExtractor<? super U2,? extends V> valueMapper, Remote.BinaryOperator<V> mergeFunction)
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to Object.equals(Object)), the value mapping function is applied to each
equal element, and the results are merged using the provided merging
function.
T - the type of the stream elementsU1 - the type of the objects to extract keys from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryU2 - the type of the objects to extract values from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryK - the output type of the key mapping functionV - the output type of the value mapping functionkeyMapper - a mapping function to produce keysvalueMapper - a mapping function to produce valuesmergeFunction - a merge function, used to resolve collisions between
values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)Collector which collects elements into a Map
whose keys are the result of applying a key mapping function to the input
elements, and whose values are the result of applying a value mapping
function to all input elements equal to the key and combining them using
the merge functiontoMap(ValueExtractor, ValueExtractor),
toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator, Remote.Supplier)toMap
simply use a merge function that throws unconditionally, but you can
easily write more flexible merge policies. For example, if you have a
stream of Person, and you want to produce a "phone book" mapping
name to address, but it is possible that two persons have the same name,
you can do as follows to gracefully deals with these collisions, and
produce a Map mapping names to a concatenated list of addresses:
Map<String, String> phoneBook
people.stream().collect(toMap(Person::getName,
Person::getAddress,
(s, a) -> s + ", " + a));
public static <T,U1,U2,K,V,M extends Map<K,V>> RemoteCollector<T,?,M> toMap(ValueExtractor<? super U1,? extends K> keyExtractor, ValueExtractor<? super U2,? extends V> valueExtractor, Remote.BinaryOperator<V> mergeFunction, Remote.Supplier<M> mapSupplier)
Collector that accumulates elements into a Map
whose keys and values are the result of applying the provided mapping
functions to the input elements.
If the mapped keys contains duplicates (according to Object.equals(Object)), the value mapping function is applied to each
equal element, and the results are merged using the provided merging
function. The Map is created by a provided supplier function.
T - the type of the stream elementsU1 - the type of the objects to extract keys from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryU2 - the type of the objects to extract values from, which
should be either the same as T, or the key or
value type if the T is InvocableMap.EntryK - the output type of the key mapping functionV - the output type of the value mapping functionM - the type of the resulting MapkeyExtractor - a mapping function to produce keysvalueExtractor - a mapping function to produce valuesmergeFunction - a merge function, used to resolve collisions between
values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)mapSupplier - a function which returns a new, empty Map
into which the results will be insertedCollector which collects elements into a Map
whose keys are the result of applying a key mapping function to the input
elements, and whose values are the result of applying a value mapping
function to all input elements equal to the key and combining them using
the merge functiontoMap(ValueExtractor, ValueExtractor),
toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator)public static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.IntSummaryStatistics> summarizingInt(ValueExtractor<? super U,? extends Number> extractor)
Collector which applies an int-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a mapping function to apply to each elementCollector implementing the summary-statistics reductionsummarizingDouble(ValueExtractor),
summarizingLong(ValueExtractor)public static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.LongSummaryStatistics> summarizingLong(ValueExtractor<? super U,? extends Number> extractor)
Collector which applies an long-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a mapping function to apply to each elementCollector implementing the summary-statistics reductionsummarizingDouble(ValueExtractor),
summarizingInt(ValueExtractor)public static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.DoubleSummaryStatistics> summarizingDouble(ValueExtractor<? super U,? extends Number> extractor)
Collector which applies an double-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T - the type of the stream elementsU - the type of the objects to extract from, which should be
either the same as T, or the key or value type
if the T is InvocableMap.Entryextractor - a mapping function to apply to each elementCollector implementing the summary-statistics reductionsummarizingLong(ValueExtractor),
summarizingInt(ValueExtractor)