public abstract class DistributedCollectors extends Object
DistributedCollector
that implement various
useful reduction operations, such as accumulating elements into
collections, summarizing elements according to various criteria, etc.Constructor and Description |
---|
DistributedCollectors() |
Modifier and Type | Method and Description |
---|---|
static <T> DistributedCollector<T,?,Double> |
averagingDouble(DistributedToDoubleFunction<? super T> mapper)
Returns a
DistributedCollector that produces the arithmetic mean of a double-valued
function applied to the input elements. |
static <T> DistributedCollector<T,?,Double> |
averagingInt(DistributedToIntFunction<? super T> mapper)
Returns a
DistributedCollector that produces the arithmetic mean of an integer-valued
function applied to the input elements. |
static <T> DistributedCollector<T,?,Double> |
averagingLong(DistributedToLongFunction<? super T> mapper)
Returns a
DistributedCollector that produces the arithmetic mean of a long-valued
function applied to the input elements. |
static <T,A,R,RR> DistributedCollector<T,A,RR> |
collectingAndThen(DistributedCollector<T,A,R> downstream,
DistributedFunction<R,RR> finisher)
Adapts a
DistributedCollector to perform an additional finishing
transformation. |
static <T> DistributedCollector<T,?,Long> |
counting()
Returns a
DistributedCollector accepting elements of type T that
counts the number of input elements. |
static <T,K> DistributedCollector<T,?,Map<K,List<T>>> |
groupingBy(DistributedFunction<? super T,? extends K> classifier)
Returns a
DistributedCollector 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,K,A,D> DistributedCollector<T,?,Map<K,D>> |
groupingBy(DistributedFunction<? super T,? extends K> classifier,
DistributedCollector<? super T,A,D> downstream)
Returns a
DistributedCollector 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
DistributedCollector . |
static <T,K,D,A,M extends Map<K,D>> |
groupingBy(DistributedFunction<? super T,? extends K> classifier,
DistributedSupplier<M> mapFactory,
DistributedCollector<? super T,A,D> downstream)
Returns a
DistributedCollector 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
DistributedCollector . |
static <T,K> DistributedCollector.Reducer<T,com.hazelcast.cache.ICache<K,List<T>>> |
groupingByToICache(String cacheName,
DistributedFunction<? super T,? extends K> classifier)
Returns a
Reducer implementing a "group by" operation on
input elements of type T , grouping elements according to a
classification function, and returning the results in a
new distributed Hazelcast ICache . |
static <T,K,A,D> DistributedCollector.Reducer<T,com.hazelcast.cache.ICache<K,D>> |
groupingByToICache(String cacheName,
DistributedFunction<? super T,? extends K> classifier,
DistributedCollector<? super T,A,D> downstream)
Returns a
Reducer 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
DistributedCollector . |
static <T,K> DistributedCollector.Reducer<T,com.hazelcast.core.IMap<K,List<T>>> |
groupingByToIMap(String mapName,
DistributedFunction<? super T,? extends K> classifier)
Returns a
Reducer implementing a "group by" operation on
input elements of type T , grouping elements according to a
classification function, and returning the results in a
new distributed Hazelcast IMap . |
static <T,K,A,D> DistributedCollector.Reducer<T,com.hazelcast.core.IMap<K,D>> |
groupingByToIMap(String mapName,
DistributedFunction<? super T,? extends K> classifier,
DistributedCollector<? super T,A,D> downstream)
Returns a
Reducer 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
DistributedCollector . |
static DistributedCollector<CharSequence,?,String> |
joining()
Returns a
DistributedCollector that concatenates the input elements into a
String , in encounter order. |
static DistributedCollector<CharSequence,?,String> |
joining(CharSequence delimiter)
Returns a
DistributedCollector that concatenates the input elements,
separated by the specified delimiter, in encounter order. |
static DistributedCollector<CharSequence,?,String> |
joining(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns a
DistributedCollector that concatenates the input elements,
separated by the specified delimiter, with the specified prefix and
suffix, in encounter order. |
static <T,U,A,R> DistributedCollector<T,?,R> |
mapping(DistributedFunction<? super T,? extends U> mapper,
DistributedCollector<? super U,A,R> downstream)
Adapts a
DistributedCollector 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> DistributedCollector<T,?,DistributedOptional<T>> |
maxBy(DistributedComparator<? super T> comparator)
Returns a
DistributedCollector that produces the maximal element according
to a given DistributedComparator , described as an Optional<T> . |
static <T> DistributedCollector<T,?,DistributedOptional<T>> |
minBy(DistributedComparator<? super T> comparator)
Returns a
DistributedCollector that produces the minimal element according
to a given DistributedComparator , described as an Optional<T> . |
static <T> java.util.stream.Collector<T,?,Map<Boolean,List<T>>> |
partitioningBy(DistributedPredicate<? super T> predicate)
Returns a
DistributedCollector which partitions the input elements according
to a DistributedPredicate , and organizes them into a
Map<Boolean, List<T>> . |
static <T,D,A> java.util.stream.Collector<T,?,Map<Boolean,D>> |
partitioningBy(DistributedPredicate<? super T> predicate,
DistributedCollector<? super T,A,D> downstream)
Returns a
DistributedCollector which partitions the input elements according
to a DistributedPredicate , reduces the values in each partition according to
another DistributedCollector , and organizes them into a
Map<Boolean, D> whose values are the result of the downstream
reduction. |
static <T> DistributedCollector<T,?,DistributedOptional<T>> |
reducing(DistributedBinaryOperator<T> op)
Returns a
DistributedCollector which performs a reduction of its
input elements under a specified DistributedBinaryOperator . |
static <T> DistributedCollector<T,?,T> |
reducing(T identity,
DistributedBinaryOperator<T> op)
Returns a
DistributedCollector which performs a reduction of its
input elements under a specified DistributedBinaryOperator using the
provided identity. |
static <T,U> DistributedCollector<T,?,U> |
reducing(U identity,
DistributedFunction<? super T,? extends U> mapper,
DistributedBinaryOperator<U> op)
Returns a
DistributedCollector which performs a reduction of its
input elements under a specified mapping function and
DistributedBinaryOperator . |
static <T> DistributedCollector<T,?,DoubleSummaryStatistics> |
summarizingDouble(DistributedToDoubleFunction<? super T> mapper)
Returns a
DistributedCollector which applies an double -producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T> DistributedCollector<T,?,IntSummaryStatistics> |
summarizingInt(DistributedToIntFunction<? super T> mapper)
Returns a
DistributedCollector which applies an int -producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T> DistributedCollector<T,?,LongSummaryStatistics> |
summarizingLong(DistributedToLongFunction<? super T> mapper)
Returns a
DistributedCollector which applies an long -producing
mapping function to each input element, and returns summary statistics
for the resulting values. |
static <T> DistributedCollector<T,?,Double> |
summingDouble(DistributedToDoubleFunction<? super T> mapper)
Returns a
DistributedCollector that produces the sum of a double-valued
function applied to the input elements. |
static <T> DistributedCollector<T,?,Integer> |
summingInt(DistributedToIntFunction<? super T> mapper)
Returns a
DistributedCollector that produces the sum of a integer-valued
function applied to the input elements. |
static <T> DistributedCollector<T,?,Long> |
summingLong(DistributedToLongFunction<? super T> mapper)
Returns a
DistributedCollector that produces the sum of a long-valued
function applied to the input elements. |
static <T,C extends Collection<T>> |
toCollection(DistributedSupplier<C> collectionFactory)
Returns a
DistributedCollector that accumulates the input
elements into a new Collection , in encounter order. |
static <K,U> DistributedCollector.Reducer<Map.Entry<K,U>,IStreamCache<K,U>> |
toICache(String cacheName)
Returns a
Reducer that accumulates elements into a
new distributed Hazelcast ICache whose keys and values are the keys and values of
the corresponding Cache.Entry . |
static <T,K,U> DistributedCollector.Reducer<T,IStreamCache<K,U>> |
toICache(String cacheName,
DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper)
Returns a
Reducer that accumulates elements into a
new Hazelcast ICache whose keys and values are the result of applying the provided
mapping functions to the input elements. |
static <T,K,U> DistributedCollector.Reducer<T,IStreamCache<K,U>> |
toICache(String cacheName,
DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper,
DistributedBinaryOperator<U> mergeFunction)
Returns a
Reducer that accumulates elements into a
new distributed Hazelcast ICache whose keys and values are the result of applying
the provided mapping functions to the input elements. |
static <T> DistributedCollector.Reducer<T,IStreamList<T>> |
toIList(String listName)
Returns a
Reducer that accumulates the input elements into a
new Hazelcast IList . |
static <K,U> DistributedCollector.Reducer<Map.Entry<K,U>,IStreamMap<K,U>> |
toIMap(String mapName)
Returns a
Reducer that accumulates elements into a
new distributed Hazelcast IMap whose keys and values are the keys and values of
the corresponding Map.Entry . |
static <T,K,U> DistributedCollector.Reducer<T,IStreamMap<K,U>> |
toIMap(String mapName,
DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper)
Returns a
Reducer that accumulates elements into a
new Hazelcast IMap whose keys and values are the result of applying the provided
mapping functions to the input elements. |
static <T,K,U> DistributedCollector.Reducer<T,IStreamMap<K,U>> |
toIMap(String mapName,
DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper,
DistributedBinaryOperator<U> mergeFunction)
Returns a
Reducer that accumulates elements into a
new distributed Hazelcast IMap whose keys and values are the result of applying
the provided mapping functions to the input elements. |
static <T> DistributedCollector<T,?,List<T>> |
toList()
Returns a
DistributedCollector that accumulates the input
elements into a new List . |
static <T,K,U> DistributedCollector<T,?,Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper)
Returns a
DistributedCollector 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,K,U> java.util.stream.Collector<T,?,Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper,
DistributedBinaryOperator<U> mergeFunction)
Returns a
DistributedCollector 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,K,U,M extends Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> keyMapper,
DistributedFunction<? super T,? extends U> valueMapper,
DistributedBinaryOperator<U> mergeFunction,
DistributedSupplier<M> mapSupplier)
Returns a
DistributedCollector 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> DistributedCollector<T,?,Set<T>> |
toSet()
Returns a
DistributedCollector that accumulates the input
elements into a new Set . |
public static <T,C extends Collection<T>> DistributedCollector<T,?,C> toCollection(DistributedSupplier<C> collectionFactory)
DistributedCollector
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 Collection
collectionFactory
- a DistributedSupplier
which returns a new, empty
Collection
of the appropriate typeDistributedCollector
which collects all the input elements into a
Collection
, in encounter orderpublic static <T> DistributedCollector<T,?,List<T>> toList()
DistributedCollector
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(DistributedSupplier)
.T
- the type of the input elementsDistributedCollector
which collects all the input elements into a
List
, in encounter orderpublic static <T> DistributedCollector<T,?,Set<T>> toSet()
DistributedCollector
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(DistributedSupplier)
.
This is an unordered
Collector.
T
- the type of the input elementsDistributedCollector
which collects all the input elements
into a Set
public static DistributedCollector<CharSequence,?,String> joining()
DistributedCollector
that concatenates the input elements into a
String
, in encounter order.DistributedCollector
that concatenates the input elements into a
String
, in encounter orderpublic static DistributedCollector<CharSequence,?,String> joining(CharSequence delimiter)
DistributedCollector
that concatenates the input elements,
separated by the specified delimiter, in encounter order.delimiter
- the delimiter to be used between each elementDistributedCollector
which concatenates CharSequence elements,
separated by the specified delimiter, in encounter orderpublic static DistributedCollector<CharSequence,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
DistributedCollector
that concatenates the input elements,
separated by the specified delimiter, with the specified prefix and
suffix, in encounter order.delimiter
- the delimiter to be used between each elementprefix
- the sequence of characters to be used at the beginning
of the joined resultsuffix
- the sequence of characters to be used at the end
of the joined resultDistributedCollector
which concatenates CharSequence elements,
separated by the specified delimiter, in encounter orderpublic static <T,U,A,R> DistributedCollector<T,?,R> mapping(DistributedFunction<? super T,? extends U> mapper, DistributedCollector<? super U,A,R> downstream)
DistributedCollector
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 valuespublic static <T,A,R,RR> DistributedCollector<T,A,RR> collectingAndThen(DistributedCollector<T,A,R> downstream, DistributedFunction<R,RR> finisher)
DistributedCollector
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> DistributedCollector<T,?,Long> counting()
DistributedCollector
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 elementsDistributedCollector
that counts the input elementspublic static <T> DistributedCollector<T,?,DistributedOptional<T>> minBy(DistributedComparator<? super T> comparator)
DistributedCollector
that produces the minimal element according
to a given DistributedComparator
, described as an Optional<T>
.T
- the type of the input elementscomparator
- a DistributedComparator
for comparing elementsDistributedCollector
that produces the minimal valuepublic static <T> DistributedCollector<T,?,DistributedOptional<T>> maxBy(DistributedComparator<? super T> comparator)
DistributedCollector
that produces the maximal element according
to a given DistributedComparator
, described as an Optional<T>
.T
- the type of the input elementscomparator
- a DistributedComparator
for comparing elementsDistributedCollector
that produces the maximal valuepublic static <T> DistributedCollector<T,?,Integer> summingInt(DistributedToIntFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,Long> summingLong(DistributedToLongFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,Double> summingDouble(DistributedToDoubleFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,Double> averagingInt(DistributedToIntFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,Double> averagingLong(DistributedToLongFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,Double> averagingDouble(DistributedToDoubleFunction<? super T> mapper)
DistributedCollector
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 input elementsmapper
- a function extracting the property to be summedDistributedCollector
that produces the sum of a derived propertypublic static <T> DistributedCollector<T,?,T> reducing(T identity, DistributedBinaryOperator<T> op)
DistributedCollector
which performs a reduction of its
input elements under a specified DistributedBinaryOperator
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 DistributedBinaryOperator<T>
used to reduce the input elementsDistributedCollector
which implements the reduction operationreducing(DistributedBinaryOperator)
,
reducing(Object, DistributedFunction, DistributedBinaryOperator)
public static <T> DistributedCollector<T,?,DistributedOptional<T>> reducing(DistributedBinaryOperator<T> op)
DistributedCollector
which performs a reduction of its
input elements under a specified DistributedBinaryOperator
. The result
is described as an Optional<T>
.T
- element type for the input and output of the reductionop
- a DistributedBinaryOperator<T>
used to reduce the input elementsDistributedCollector
which implements the reduction operationreducing(Object, DistributedBinaryOperator)
,
reducing(Object, DistributedFunction, DistributedBinaryOperator)
public static <T,U> DistributedCollector<T,?,U> reducing(U identity, DistributedFunction<? super T,? extends U> mapper, DistributedBinaryOperator<U> op)
DistributedCollector
which performs a reduction of its
input elements under a specified mapping function and
DistributedBinaryOperator
. This is a generalization of
reducing(Object, DistributedBinaryOperator)
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 DistributedBinaryOperator<U>
used to reduce the mapped valuesDistributedCollector
implementing the map-reduce operationreducing(Object, DistributedBinaryOperator)
,
reducing(DistributedBinaryOperator)
public static <T,K> DistributedCollector<T,?,Map<K,List<T>>> groupingBy(DistributedFunction<? super T,? extends K> classifier)
DistributedCollector
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 List
s 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 input elementsK
- the type of the keysclassifier
- the classifier function mapping input elements to keysDistributedCollector
implementing the group-by operationgroupingBy(DistributedFunction, DistributedCollector)
,
groupingBy(DistributedFunction, DistributedSupplier, DistributedCollector)
public static <T,K,A,D> DistributedCollector<T,?,Map<K,D>> groupingBy(DistributedFunction<? super T,? extends K> classifier, DistributedCollector<? super T,A,D> downstream)
DistributedCollector
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
DistributedCollector
.
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 input elementsK
- 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 DistributedCollector
implementing the downstream reductionDistributedCollector
implementing the cascaded group-by operationgroupingBy(DistributedFunction)
,
groupingBy(DistributedFunction, DistributedSupplier, DistributedCollector)
public static <T,K,D,A,M extends Map<K,D>> DistributedCollector<T,?,M> groupingBy(DistributedFunction<? super T,? extends K> classifier, DistributedSupplier<M> mapFactory, DistributedCollector<? super T,A,D> downstream)
DistributedCollector
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
DistributedCollector
. 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 input elementsK
- 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 Map
classifier
- a classifier function mapping input elements to keysdownstream
- a DistributedCollector
implementing the downstream reductionmapFactory
- a function which, when called, produces a new empty
Map
of the desired typeDistributedCollector
implementing the cascaded group-by operationgroupingBy(DistributedFunction, DistributedCollector)
,
groupingBy(DistributedFunction)
public static <T> java.util.stream.Collector<T,?,Map<Boolean,List<T>>> partitioningBy(DistributedPredicate<? super T> predicate)
DistributedCollector
which partitions the input elements according
to a DistributedPredicate
, and organizes them into a
Map<Boolean, List<T>>
.
There are no guarantees on the type, mutability,
serializability, or thread-safety of the Map
returned.
T
- the type of the input elementspredicate
- a predicate used for classifying input elementsDistributedCollector
implementing the partitioning operationpartitioningBy(DistributedPredicate, DistributedCollector)
public static <T,D,A> java.util.stream.Collector<T,?,Map<Boolean,D>> partitioningBy(DistributedPredicate<? super T> predicate, DistributedCollector<? super T,A,D> downstream)
DistributedCollector
which partitions the input elements according
to a DistributedPredicate
, reduces the values in each partition according to
another DistributedCollector
, and organizes them into a
Map<Boolean, D>
whose values are the result of the downstream
reduction.
There are no guarantees on the type, mutability,
serializability, or thread-safety of the Map
returned.
T
- the type of the input elementsA
- the intermediate accumulation type of the downstream collectorD
- the result type of the downstream reductionpredicate
- a predicate used for classifying input elementsdownstream
- a DistributedCollector
implementing the downstream
reductionDistributedCollector
implementing the cascaded partitioning
operationpartitioningBy(DistributedPredicate)
public static <T,K,U> DistributedCollector<T,?,Map<K,U>> toMap(DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper)
DistributedCollector
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(DistributedFunction, DistributedFunction,
DistributedBinaryOperator)
instead.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesDistributedCollector
which collects elements into a Map
whose keys and values are the result of applying mapping functions to
the input elementstoMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator,
DistributedSupplier)
public static <T,K,U> java.util.stream.Collector<T,?,Map<K,U>> toMap(DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper, DistributedBinaryOperator<U> mergeFunction)
DistributedCollector
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 input elementsK
- the output type of the key mapping functionU
- 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,
java.util.function.BiFunction)
DistributedCollector
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(DistributedFunction, DistributedFunction)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator,
DistributedSupplier)
public static <T,K,U,M extends Map<K,U>> DistributedCollector<T,?,M> toMap(DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper, DistributedBinaryOperator<U> mergeFunction, DistributedSupplier<M> mapSupplier)
DistributedCollector
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 input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionM
- the type of the resulting Map
keyMapper
- 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, java.util.function.BiFunction)
mapSupplier
- a function which returns a new, empty Map
into
which the results will be insertedDistributedCollector
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(DistributedFunction, DistributedFunction)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
public static <T> DistributedCollector<T,?,IntSummaryStatistics> summarizingInt(DistributedToIntFunction<? super T> mapper)
DistributedCollector
which applies an int
-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T
- the type of the input elementsmapper
- a mapping function to apply to each elementDistributedCollector
implementing the summary-statistics reductionsummarizingDouble(DistributedToDoubleFunction)
,
summarizingLong(DistributedToLongFunction)
public static <T> DistributedCollector<T,?,LongSummaryStatistics> summarizingLong(DistributedToLongFunction<? super T> mapper)
DistributedCollector
which applies an long
-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T
- the type of the input elementsmapper
- the mapping function to apply to each elementDistributedCollector
implementing the summary-statistics reductionsummarizingDouble(DistributedToDoubleFunction)
,
summarizingInt(DistributedToIntFunction)
public static <T> DistributedCollector<T,?,DoubleSummaryStatistics> summarizingDouble(DistributedToDoubleFunction<? super T> mapper)
DistributedCollector
which applies an double
-producing
mapping function to each input element, and returns summary statistics
for the resulting values.T
- the type of the input elementsmapper
- a mapping function to apply to each elementDistributedCollector
implementing the summary-statistics reductionsummarizingLong(DistributedToLongFunction)
,
summarizingInt(DistributedToIntFunction)
public static <T,K,U> DistributedCollector.Reducer<T,IStreamMap<K,U>> toIMap(String mapName, DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper)
Reducer
that accumulates elements into a
new Hazelcast IMap
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)
), only one of the mapped values will be in the final map,
and the others will be dropped. If the mapped keys may have duplicates, use
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
instead.
The returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionmapName
- Name of the map to store the resultskeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesReducer
which collects elements into a IMap
whose keys and values are the result of applying mapping functions to
the input elementstoIMap(String, DistributedFunction, DistributedFunction, DistributedBinaryOperator)
public static <K,U> DistributedCollector.Reducer<Map.Entry<K,U>,IStreamMap<K,U>> toIMap(String mapName)
Reducer
that accumulates elements into a
new distributed Hazelcast IMap
whose keys and values are the keys and values of
the corresponding Map.Entry
.
*
If the mapped keys contains duplicates (according to
Object.equals(Object)
), only one of the mapped values will be in the final map,
and the others will be dropped. If the mapped keys may have duplicates, use
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
instead.
The returned collector may not be used as a downstream collector.
K
- The type of the key in Map.Entry
U
- The type of the value in Map.Entry
mapName
- Name of the map to store the resultsReducer
that accumulates elements into a
Hazelcast IMap
whose keys and values are the keys and values of the corresponding
Map.Entry
.toIMap(String, DistributedFunction, DistributedFunction)
,
toIMap(String, DistributedFunction, DistributedFunction, DistributedBinaryOperator)
public static <T,K,U> DistributedCollector.Reducer<T,IStreamMap<K,U>> toIMap(String mapName, DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper, DistributedBinaryOperator<U> mergeFunction)
Reducer
that accumulates elements into a
new distributed Hazelcast IMap
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 returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functionmapName
- Name of the map to store the resultskeyMapper
- 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,
java.util.function.BiFunction)
Reducer
which collects elements into a distributed
IMap
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 functiontoIMap(String, DistributedFunction, DistributedFunction)
public static <T,K,U> DistributedCollector.Reducer<T,IStreamCache<K,U>> toICache(String cacheName, DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper)
Reducer
that accumulates elements into a
new Hazelcast ICache
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)
), only one of the mapped values will be in the final map,
and the others will be dropped. If the mapped keys may have duplicates, use
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
instead.
The returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functioncacheName
- Name of the cache to store the resultskeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesReducer
which collects elements into a ICache
whose keys and values are the result of applying mapping functions to
the input elementstoICache(String, DistributedFunction, DistributedFunction, DistributedBinaryOperator)
public static <K,U> DistributedCollector.Reducer<Map.Entry<K,U>,IStreamCache<K,U>> toICache(String cacheName)
Reducer
that accumulates elements into a
new distributed Hazelcast ICache
whose keys and values are the keys and values of
the corresponding Cache.Entry
.
*
If the mapped keys contains duplicates (according to
Object.equals(Object)
), only one of the mapped values will be in the final map,
and the others will be dropped. If the mapped keys may have duplicates, use
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
instead.
The returned collector may not be used as a downstream collector.
K
- The type of the key in Cache.Entry
U
- The type of the value in Cache.Entry
cacheName
- Name of the cache to store the resultsReducer
that accumulates elements into a
Hazelcast ICache
whose keys and values are the keys and values of the corresponding
Cache.Entry
.toICache(String, DistributedFunction, DistributedFunction)
,
toICache(String, DistributedFunction, DistributedFunction, DistributedBinaryOperator)
public static <T,K,U> DistributedCollector.Reducer<T,IStreamCache<K,U>> toICache(String cacheName, DistributedFunction<? super T,? extends K> keyMapper, DistributedFunction<? super T,? extends U> valueMapper, DistributedBinaryOperator<U> mergeFunction)
Reducer
that accumulates elements into a
new distributed Hazelcast ICache
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 returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the output type of the key mapping functionU
- the output type of the value mapping functioncacheName
- Name of the cache to store the resultskeyMapper
- 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,
java.util.function.BiFunction)
Reducer
which collects elements into a distributed
ICache
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 functiontoICache(String, DistributedFunction, DistributedFunction)
public static <T> DistributedCollector.Reducer<T,IStreamList<T>> toIList(String listName)
Reducer
that accumulates the input elements into a
new Hazelcast IList
.
The returned collector may not be used as a downstream collector.
T
- the type of the input elementslistName
- Name of the list to store the resultsDistributedCollector
which collects all the input elements into a
Hazelcast IList
, in encounter orderpublic static <T,K> DistributedCollector.Reducer<T,com.hazelcast.core.IMap<K,List<T>>> groupingByToIMap(String mapName, DistributedFunction<? super T,? extends K> classifier)
Reducer
implementing a "group by" operation on
input elements of type T
, grouping elements according to a
classification function, and returning the results in a
new distributed Hazelcast IMap
.
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 List
s containing the
input elements which map to the associated key under the classification
function.
The returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the type of the keysmapName
- Name of the map to store the resultsclassifier
- the classifier function mapping input elements to keysReducer
implementing the group-by operationgroupingByToIMap(String, DistributedFunction, DistributedCollector)
public static <T,K,A,D> DistributedCollector.Reducer<T,com.hazelcast.core.IMap<K,D>> groupingByToIMap(String mapName, DistributedFunction<? super T,? extends K> classifier, DistributedCollector<? super T,A,D> downstream)
Reducer
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
DistributedCollector
.
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 new
Hazelcast distributed IMap<K, D>
.
For example, to compute the set of last names of people in each city:
IMap<City, Set<String>> namesByCity
= people.stream().collect(groupingBy(Person::getCity,
mapping(Person::getLastName, toSet())));
T
- the type of the input elementsK
- the type of the keysA
- the intermediate accumulation type of the downstream collectorD
- the result type of the downstream reductionmapName
- Name of the map to store the resultsclassifier
- a classifier function mapping input elements to keysdownstream
- a DistributedCollector
implementing the downstream reductionReducer
implementing the cascaded group-by operationgroupingByToIMap(String, DistributedFunction)
public static <T,K> DistributedCollector.Reducer<T,com.hazelcast.cache.ICache<K,List<T>>> groupingByToICache(String cacheName, DistributedFunction<? super T,? extends K> classifier)
Reducer
implementing a "group by" operation on
input elements of type T
, grouping elements according to a
classification function, and returning the results in a
new distributed Hazelcast ICache
.
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 List
s containing the
input elements which map to the associated key under the classification
function.
The returned collector may not be used as a downstream collector.
T
- the type of the input elementsK
- the type of the keyscacheName
- Name of the cache to store the resultsclassifier
- the classifier function mapping input elements to keysReducer
implementing the group-by operationgroupingByToICache(String, DistributedFunction, DistributedCollector)
public static <T,K,A,D> DistributedCollector.Reducer<T,com.hazelcast.cache.ICache<K,D>> groupingByToICache(String cacheName, DistributedFunction<? super T,? extends K> classifier, DistributedCollector<? super T,A,D> downstream)
Reducer
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
DistributedCollector
.
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 new
Hazelcast distributed ICache<K, D>
.
For example, to compute the set of last names of people in each city:
ICache<City, Set<String>> namesByCity
= people.stream().collect(groupingBy(Person::getCity,
mapping(Person::getLastName, toSet())));
T
- the type of the input elementsK
- the type of the keysA
- the intermediate accumulation type of the downstream collectorD
- the result type of the downstream reductioncacheName
- Name of the cache to store the resultsclassifier
- a classifier function mapping input elements to keysdownstream
- a DistributedCollector
implementing the downstream reductionReducer
implementing the cascaded group-by operationgroupingByToICache(String, DistributedFunction)
Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.