Class RemoteCollectors
- java.lang.Object
- 
- com.tangosol.util.stream.RemoteCollectors
 
- 
 public abstract class RemoteCollectors extends Object Static factory for variousRemoteCollectors that can be executed in parallel in a distributed environment.- Since:
- 12.2.1
- Author:
- as 2014.10.01
- See Also:
- RemoteCollector,- Collectors
 
- 
- 
Constructor SummaryConstructors Constructor Description RemoteCollectors()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
 RemoteCollector<T,?,Double>averagingDouble(ValueExtractor<? super U,? extends Number> extractor)Returns aCollectorthat 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 aCollectorthat 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 aCollectorthat 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 aCollectorto perform an additional finishing transformation.static <T> RemoteCollector<T,?,Long>counting()Returns aCollectoraccepting elements of typeTthat counts the number of input elements.static <T,U,K>
 RemoteCollector<T,?,Map<K,List<T>>>groupingBy(ValueExtractor<? super U,? extends K> classifier)Returns aCollectorimplementing a "group by" operation on input elements of typeT, grouping elements according to a classification function, and returning the results in aMap.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)Returns aCollectorimplementing a cascaded "group by" operation on input elements of typeT, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector.static <T,U,K,A,D>
 RemoteCollector<T,?,Map<K,D>>groupingBy(ValueExtractor<? super U,? extends K> classifier, RemoteCollector<? super T,A,D> downstream)Returns aCollectorimplementing a cascaded "group by" operation on input elements of typeT, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector.static <T,U,A,R>
 RemoteCollector<T,A,R>mapping(Remote.Function<? super T,? extends U> mapper, RemoteCollector<? super U,A,R> downstream)Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a mapping function to each input element before accumulation.static <T> RemoteCollector<T,?,Optional<T>>maxBy(Remote.Comparator<? super T> comparator)Returns aCollectorthat produces the maximal element according to a givenComparator, described as anOptional<T>.static <T,E extends Comparable<? super E>>
 RemoteCollector<T,?,Optional<T>>maxBy(ValueExtractor<? super T,? extends E> comparable)Returns aCollectorthat produces the maximal element according to a givenComparableattribute, described as anOptional<T>.static <T> RemoteCollector<T,?,Optional<T>>minBy(Remote.Comparator<? super T> comparator)Returns aCollectorthat produces the minimal element according to a givenComparator, described as anOptional<T>.static <T,E extends Comparable<? super E>>
 RemoteCollector<T,?,Optional<T>>minBy(ValueExtractor<? super T,? extends E> comparable)Returns aCollectorthat produces the minimal element according to a givenComparableattribute, described as anOptional<T>.static <T> RemoteCollector<T,?,Optional<T>>reducing(Remote.BinaryOperator<T> op)Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperator.static <T> RemoteCollector<T,SimpleHolder<T>,T>reducing(T identity, Remote.BinaryOperator<T> op)Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperatorusing 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 aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator.static <T,U>
 RemoteCollector<T,?,U>reducing(U identity, Remote.Function<? super T,? extends U> mapper, Remote.BinaryOperator<U> op)Returns aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator.static <T,U>
 RemoteCollector<T,?,com.tangosol.internal.util.DoubleSummaryStatistics>summarizingDouble(ValueExtractor<? super U,? extends Number> extractor)Returns aCollectorwhich applies andouble-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 aCollectorwhich applies anint-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 aCollectorwhich applies anlong-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 aCollectorthat 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 aCollectorthat 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 aCollectorthat produces the sum of a long-valued function applied to the input elements.static <T,C extends Collection<T>>
 RemoteCollector<T,?,C>toCollection(Remote.Supplier<C> supplier)Returns aCollectorthat accumulates the input elements into a newCollection, in encounter order.static <T> RemoteCollector<T,?,List<T>>toList()Returns aCollectorthat accumulates the input elements into a newList.static <T,U1,U2,K,V>
 RemoteCollector<T,?,Map<K,V>>toMap(ValueExtractor<? super U1,? extends K> keyMapper, ValueExtractor<? super U2,? extends V> valueMapper)Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.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)Returns aCollectorthat accumulates elements into aMapwhose 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>>
 RemoteCollector<T,?,M>toMap(ValueExtractor<? super U1,? extends K> keyExtractor, ValueExtractor<? super U2,? extends V> valueExtractor, Remote.BinaryOperator<V> mergeFunction, Remote.Supplier<M> mapSupplier)Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.static <T> RemoteCollector<T,?,Set<T>>toSet()Returns aCollectorthat accumulates the input elements into a newSet.static <T> RemoteCollector<T,?,Collection<T>>toSortedBag()Returns aCollectorthat accumulates the input elements into a newSortedBag.static <T> RemoteCollector<T,?,Collection<T>>toSortedBag(Remote.Comparator<? super T> comparator)Returns aCollectorthat accumulates the input elements into a newSortedBag.static <T,E extends Comparable<? super E>>
 RemoteCollector<T,?,Collection<T>>toSortedBag(ValueExtractor<? super T,? extends E> comparable)Returns aCollectorthat accumulates the input elements into a newSortedBag.static <T> RemoteCollector<T,?,Collection<T>>toSortedBag(Comparator<? super T> comparator)Returns aCollectorthat accumulates the input elements into a newSortedBag.static <T> RemoteCollector<T,?,SortedSet<T>>toSortedSet()Returns aCollectorthat accumulates the input elements into a newSortedSet.static <T> RemoteCollector<T,?,SortedSet<T>>toSortedSet(Remote.Comparator<? super T> comparator)Returns aCollectorthat accumulates the input elements into a newSortedSet.static <T,E extends Comparable<? super E>>
 RemoteCollector<T,?,SortedSet<T>>toSortedSet(ValueExtractor<? super T,? extends E> comparable)Returns aCollectorthat accumulates the input elements into a newSortedSet.static <T> RemoteCollector<T,?,SortedSet<T>>toSortedSet(Comparator<? super T> comparator)Returns aCollectorthat accumulates the input elements into a newSortedSet.
 
- 
- 
- 
Method Detail- 
toCollectionpublic static <T,C extends Collection<T>> RemoteCollector<T,?,C> toCollection(Remote.Supplier<C> supplier) Returns aCollectorthat accumulates the input elements into a newCollection, in encounter order. TheCollectionis created by the provided factory.- Type Parameters:
- T- the type of the input elements
- C- the type of the resulting- Collection
- Parameters:
- supplier- a- Supplierwhich returns a new, empty- Collectionof the appropriate type
- Returns:
- a Collectorwhich collects all the input elements into aCollection, in encounter order
 
 - 
toListpublic static <T> RemoteCollector<T,?,List<T>> toList() Returns aCollectorthat accumulates the input elements into a newList. There are no guarantees on the type, mutability, serializability, or thread-safety of theListreturned; if more control over the returnedListis required, usetoCollection(Remote.Supplier).- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toSortedBagpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag() Returns aCollectorthat accumulates the input elements into a newSortedBag.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toSortedBagpublic static <T,E extends Comparable<? super E>> RemoteCollector<T,?,Collection<T>> toSortedBag(ValueExtractor<? super T,? extends E> comparable) Returns aCollectorthat accumulates the input elements into a newSortedBag.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparable- a- ValueExtractorthat returns a- Comparablevalue
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toSortedBagpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag(Comparator<? super T> comparator) Returns aCollectorthat accumulates the input elements into a newSortedBag.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a comparator for type T
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toSortedBagpublic static <T> RemoteCollector<T,?,Collection<T>> toSortedBag(Remote.Comparator<? super T> comparator) Returns aCollectorthat accumulates the input elements into a newSortedBag.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a comparator for type T
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toSetpublic static <T> RemoteCollector<T,?,Set<T>> toSet() Returns aCollectorthat accumulates the input elements into a newSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSetreturned; if more control over the returnedSetis required, usetoCollection(Remote.Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aSet
 
 - 
toSortedSetpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet() Returns aCollectorthat accumulates the input elements into a newSortedSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSortedSetreturned; if more control over the returnedSortedSetis required, usetoCollection(Remote.Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aSortedSet
 
 - 
toSortedSetpublic static <T,E extends Comparable<? super E>> RemoteCollector<T,?,SortedSet<T>> toSortedSet(ValueExtractor<? super T,? extends E> comparable) Returns aCollectorthat accumulates the input elements into a newSortedSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSortedSetreturned; if more control over the returnedSortedSetis required, usetoCollection(Remote.Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparable- a- ValueExtractorthat returns a- Comparablevalue
- Returns:
- a Collectorwhich collects all the input elements into aSortedSet
 
 - 
toSortedSetpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet(Comparator<? super T> comparator) Returns aCollectorthat accumulates the input elements into a newSortedSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSortedSetreturned; if more control over the returnedSortedSetis required, usetoCollection(Remote.Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a comparator for type T
- Returns:
- a Collectorwhich collects all the input elements into aSortedSet
 
 - 
toSortedSetpublic static <T> RemoteCollector<T,?,SortedSet<T>> toSortedSet(Remote.Comparator<? super T> comparator) Returns aCollectorthat accumulates the input elements into a newSortedSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSortedSetreturned; if more control over the returnedSortedSetis required, usetoCollection(Remote.Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a comparator for type T
- Returns:
- a Collectorwhich collects all the input elements into aSortedSet
 
 - 
mappingpublic static <T,U,A,R> RemoteCollector<T,A,R> mapping(Remote.Function<? super T,? extends U> mapper, RemoteCollector<? super U,A,R> downstream) Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a mapping function to each input element before accumulation.- Type Parameters:
- T- the type of the input elements
- U- type of elements accepted by downstream collector
- A- intermediate accumulation type of the downstream collector
- R- result type of collector
- Parameters:
- mapper- a function to be applied to the input elements
- downstream- a collector which will accept mapped values
- Returns:
- a collector which applies the mapping function to the input elements and provides the mapped results to the downstream collector
- API Note:
- The mapping()collectors are most useful when used in a multi-level reduction, such as downstream of agroupingByorpartitioningBy. For example, given a stream ofPerson, 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())));
 
 - 
collectingAndThenpublic static <T,A,R,RR> RemoteCollector<T,A,RR> collectingAndThen(RemoteCollector<T,A,R> downstream, Remote.Function<R,RR> finisher) Adapts aCollectorto perform an additional finishing transformation. For example, one could adapt thetoList()collector to always produce an immutable list with:List<String> people = people.stream().collect(collectingAndThen(toList(), Collections::unmodifiableList));- Type Parameters:
- T- the type of the input elements
- A- intermediate accumulation type of the downstream collector
- R- result type of the downstream collector
- RR- result type of the resulting collector
- Parameters:
- downstream- a collector
- finisher- a function to be applied to the final result of the downstream collector
- Returns:
- a collector which performs the action of the downstream collector, followed by an additional finishing step
 
 - 
countingpublic static <T> RemoteCollector<T,?,Long> counting() Returns aCollectoraccepting elements of typeTthat counts the number of input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorthat counts the input elements
- Implementation Requirements:
- This produces a result equivalent to:
 reducing(0L, e -> 1L, Long::sum)
 
 - 
minBypublic static <T,E extends Comparable<? super E>> RemoteCollector<T,?,Optional<T>> minBy(ValueExtractor<? super T,? extends E> comparable) Returns aCollectorthat produces the minimal element according to a givenComparableattribute, described as anOptional<T>.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparable- a- ValueExtractorthat returns a- Comparablevalue
- Returns:
- a Collectorthat produces the minimal value
- Implementation Requirements:
- This produces a result equivalent to:
 reducing(Remote.BinaryOperator.minBy(comparator))
 
 - 
minBypublic static <T> RemoteCollector<T,?,Optional<T>> minBy(Remote.Comparator<? super T> comparator) Returns aCollectorthat produces the minimal element according to a givenComparator, described as anOptional<T>.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a- Comparatorfor comparing elements
- Returns:
- a Collectorthat produces the minimal value
- Implementation Requirements:
- This produces a result equivalent to:
 reducing(Remote.BinaryOperator.minBy(comparator))
 
 - 
maxBypublic static <T,E extends Comparable<? super E>> RemoteCollector<T,?,Optional<T>> maxBy(ValueExtractor<? super T,? extends E> comparable) Returns aCollectorthat produces the maximal element according to a givenComparableattribute, described as anOptional<T>.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparable- a- ValueExtractorthat returns a- Comparablevalue
- Returns:
- a Collectorthat produces the minimal value
- Implementation Requirements:
- This produces a result equivalent to:
 reducing(Remote.BinaryOperator.minBy(comparator))
 
 - 
maxBypublic static <T> RemoteCollector<T,?,Optional<T>> maxBy(Remote.Comparator<? super T> comparator) Returns aCollectorthat produces the maximal element according to a givenComparator, described as anOptional<T>.- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a- Comparatorfor comparing elements
- Returns:
- a Collectorthat produces the maximal value
- Implementation Requirements:
- This produces a result equivalent to:
 reducing(BinaryOperator.maxBy(comparator))
 
 - 
summingIntpublic static <T,U> RemoteCollector<T,?,Integer> summingInt(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat produces the sum of a integer-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
summingLongpublic static <T,U> RemoteCollector<T,?,Long> summingLong(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat produces the sum of a long-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
summingDoublepublic static <T,U> RemoteCollector<T,?,Double> summingDouble(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat 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 NaNor the sum is at any point aNaNthen the sum will beNaN.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
averagingIntpublic static <T,U> RemoteCollector<T,?,Double> averagingInt(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat produces the arithmetic mean of an integer-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
averagingLongpublic static <T,U> RemoteCollector<T,?,Double> averagingLong(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat produces the arithmetic mean of a long-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be averaged
- Returns:
- a Collectorthat produces the average of a derived property
 
 - 
averagingDoublepublic static <T,U> RemoteCollector<T,?,Double> averagingDouble(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorthat 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 NaNor the sum is at any point aNaNthen the average will beNaN.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
- Implementation Note:
- The doubleformat 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.
 
 - 
reducingpublic static <T> RemoteCollector<T,SimpleHolder<T>,T> reducing(T identity, Remote.BinaryOperator<T> op) Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperatorusing the provided identity.- Type Parameters:
- T- element type for the input and output of the reduction
- Parameters:
- identity- 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 elements
- Returns:
- a Collectorwhich implements the reduction operation
- See Also:
- reducing(Remote.BinaryOperator),- reducing(Object, Remote.Function, Remote.BinaryOperator)
- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple reduction on a stream, useRemoteStream.reduce(Object, BinaryOperator)} instead.
 
 - 
reducingpublic static <T> RemoteCollector<T,?,Optional<T>> reducing(Remote.BinaryOperator<T> op) Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperator. The result is described as anOptional<T>.- Type Parameters:
- T- element type for the input and output of the reduction
- Parameters:
- op- a- BinaryOperator<T>used to reduce the input elements
- Returns:
- a Collectorwhich implements the reduction operation
- See Also:
- reducing(Object, Remote.BinaryOperator),- reducing(Object, Remote.Function, Remote.BinaryOperator)
- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple reduction on a stream, useRemoteStream.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))));
 
 - 
reducingpublic static <T,U> RemoteCollector<T,?,U> reducing(U identity, Remote.Function<? super T,? extends U> mapper, Remote.BinaryOperator<U> op) Returns aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator. This is a generalization ofreducing(Object, Remote.BinaryOperator)which allows a transformation of the elements before reduction.- Type Parameters:
- T- the type of the input elements
- U- the type of the mapped values
- Parameters:
- identity- 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 value
- op- a- BinaryOperator<U>used to reduce the mapped values
- Returns:
- a Collectorimplementing the map-reduce operation
- See Also:
- reducing(Object, Remote.BinaryOperator),- reducing(Remote.BinaryOperator)
- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple map-reduce on a stream, useRemoteStream.map(Function)andRemoteStream.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))));
 
 - 
reducingpublic static <T,U> RemoteCollector<T,?,U> reducing(U identity, Remote.BiFunction<? super U,? super T,? extends U> mapper, Remote.BinaryOperator<U> op) Returns aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator. This is a generalization ofreducing(Object, Remote.BinaryOperator)which allows a transformation of the elements before reduction.- Type Parameters:
- T- the type of the input elements
- U- the type of the mapped values
- Parameters:
- identity- 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 value
- op- a- BinaryOperator<U>used to reduce the mapped values
- Returns:
- a Collectorimplementing the map-reduce operation
- See Also:
- reducing(Object, Remote.BinaryOperator),- reducing(Remote.BinaryOperator)
- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple map-reduce on a stream, useRemoteStream.map(Function)andRemoteStream.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))));
 
 - 
groupingBypublic static <T,U,K> RemoteCollector<T,?,Map<K,List<T>>> groupingBy(ValueExtractor<? super U,? extends K> classifier) Returns aCollectorimplementing a "group by" operation on input elements of typeT, grouping elements according to a classification function, and returning the results in aMap.The classification function maps elements to some key type K. The collector produces aMap<K, List<T>>whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values areLists 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 MaporListobjects returned.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- K- the type of the keys
- Parameters:
- classifier- the classifier function mapping input elements to keys
- Returns:
- a Collectorimplementing the group-by operation
- See Also:
- groupingBy(ValueExtractor, RemoteCollector),- groupingBy(ValueExtractor, Remote.Supplier, RemoteCollector)
- Implementation Requirements:
- This produces a result similar to:
 groupingBy(classifier, toList());
 
 - 
groupingBypublic static <T,U,K,A,D> RemoteCollector<T,?,Map<K,D>> groupingBy(ValueExtractor<? super U,? extends K> classifier, RemoteCollector<? super T,A,D> downstream) Returns aCollectorimplementing a cascaded "group by" operation on input elements of typeT, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector.The classification function maps elements to some key type K. The downstream collector operates on elements of typeTand produces a result of typeD. The resulting collector produces aMap<K, D>.There are no guarantees on the type, mutability, serializability, or thread-safety of the Mapreturned.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())));- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- K- the type of the keys
- A- the intermediate accumulation type of the downstream collector
- D- the result type of the downstream reduction
- Parameters:
- classifier- a classifier function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- Returns:
- a Collectorimplementing the cascaded group-by operation
- See Also:
- groupingBy(ValueExtractor),- groupingBy(ValueExtractor, Remote.Supplier, RemoteCollector)
 
 - 
groupingBypublic 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) Returns aCollectorimplementing a cascaded "group by" operation on input elements of typeT, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector. TheMapproduced 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 typeTand produces a result of typeD. The resulting collector produces aMap<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())));- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- K- the type of the keys
- A- the intermediate accumulation type of the downstream collector
- D- the result type of the downstream reduction
- M- the type of the resulting- Map
- Parameters:
- extractor- an extractor function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- mapFactory- a function which, when called, produces a new empty- Mapof the desired type
- Returns:
- a Collectorimplementing the cascaded group-by operation
- See Also:
- groupingBy(ValueExtractor, RemoteCollector),- groupingBy(ValueExtractor)
 
 - 
toMappublic static <T,U1,U2,K,V> RemoteCollector<T,?,Map<K,V>> toMap(ValueExtractor<? super U1,? extends K> keyMapper, ValueExtractor<? super U2,? extends V> valueMapper) Returns aCollectorthat accumulates elements into aMapwhose 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)), anIllegalStateExceptionis thrown when the collection operation is performed. If the mapped keys may have duplicates, usetoMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator)instead.- Type Parameters:
- T- the type of the stream elements
- U1- 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- Tis- InvocableMap.Entry
- U2- 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- Tis- InvocableMap.Entry
- K- the output type of the key mapping function
- V- the output type of the value mapping function
- Parameters:
- keyMapper- a mapping function to produce keys
- valueMapper- a mapping function to produce values
- Returns:
- a Collectorwhich collects elements into aMapwhose keys and values are the result of applying mapping functions to the input elements
- See Also:
- toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator),- toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator, Remote.Supplier)
- API Note:
- It is common for either the key or the value to be the input
 elements. In this case, the utility method Function.identity()may be helpful. For example, the following produces aMapmapping students to their grade point average:
 And the following produces aMap<Student, Double> studentToGPA students.stream().collect(toMap(Functions.identity(), student -> computeGPA(student)));Mapmapping a unique identifier to students:Map<String, Student> studentIdToStudent students.stream().collect(toMap(Student::getId, Functions.identity());
 
 - 
toMappublic 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) Returns aCollectorthat accumulates elements into aMapwhose 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.- Type Parameters:
- T- the type of the stream elements
- U1- 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- Tis- InvocableMap.Entry
- U2- 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- Tis- InvocableMap.Entry
- K- the output type of the key mapping function
- V- the output type of the value mapping function
- Parameters:
- keyMapper- a mapping function to produce keys
- valueMapper- a mapping function to produce values
- mergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied to- Map.merge(Object, Object, BiFunction)
- Returns:
- a Collectorwhich collects elements into aMapwhose 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 function
- See Also:
- toMap(ValueExtractor, ValueExtractor),- toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator, Remote.Supplier)
- API Note:
- There are multiple ways to deal with collisions between multiple
 elements mapping to the same key.  The other forms of toMapsimply use a merge function that throws unconditionally, but you can easily write more flexible merge policies. For example, if you have a stream ofPerson, 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 aMapmapping names to a concatenated list of addresses:Map<String, String> phoneBook people.stream().collect(toMap(Person::getName, Person::getAddress, (s, a) -> s + ", " + a));
 
 - 
toMappublic 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) Returns aCollectorthat accumulates elements into aMapwhose 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. TheMapis created by a provided supplier function.- Type Parameters:
- T- the type of the stream elements
- U1- 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- Tis- InvocableMap.Entry
- U2- 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- Tis- InvocableMap.Entry
- K- the output type of the key mapping function
- V- the output type of the value mapping function
- M- the type of the resulting- Map
- Parameters:
- keyExtractor- a mapping function to produce keys
- valueExtractor- a mapping function to produce values
- mergeFunction- 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- Mapinto which the results will be inserted
- Returns:
- a Collectorwhich collects elements into aMapwhose 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 function
- See Also:
- toMap(ValueExtractor, ValueExtractor),- toMap(ValueExtractor, ValueExtractor, Remote.BinaryOperator)
 
 - 
summarizingIntpublic static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.IntSummaryStatistics> summarizingInt(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorwhich applies anint-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingDouble(ValueExtractor),- summarizingLong(ValueExtractor)
 
 - 
summarizingLongpublic static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.LongSummaryStatistics> summarizingLong(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorwhich applies anlong-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingDouble(ValueExtractor),- summarizingInt(ValueExtractor)
 
 - 
summarizingDoublepublic static <T,U> RemoteCollector<T,?,com.tangosol.internal.util.DoubleSummaryStatistics> summarizingDouble(ValueExtractor<? super U,? extends Number> extractor) Returns aCollectorwhich applies andouble-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the stream elements
- U- the type of the objects to extract from, which should be either the same as- T, or the key or value type if the- Tis- InvocableMap.Entry
- Parameters:
- extractor- a mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingLong(ValueExtractor),- summarizingInt(ValueExtractor)
 
 
- 
 
-