public final class AggregateOperations extends Object
Modifier and Type | Method and Description |
---|---|
static <T,A1,A2,R1,R2> |
allOf(AggregateOperation1<? super T,A1,R1> op1,
AggregateOperation1<? super T,A2,R2> op2)
Convenience for
allOf(AggregateOperation1, AggregateOperation1,
DistributedBiFunction) with identity finish. |
static <T,A1,A2,A3,R1,R2,R3> |
allOf(AggregateOperation1<? super T,A1,R1> op1,
AggregateOperation1<? super T,A2,R2> op2,
AggregateOperation1<? super T,A3,R3> op3)
Convenience for
allOf(AggregateOperation1, AggregateOperation1,
AggregateOperation1, DistributedTriFunction) with identity finisher. |
static <T,A1,A2,A3,R1,R2,R3,R> |
allOf(AggregateOperation1<? super T,A1,R1> op1,
AggregateOperation1<? super T,A2,R2> op2,
AggregateOperation1<? super T,A3,R3> op3,
DistributedTriFunction<? super R1,? super R2,? super R3,R> finishFn)
Returns composite aggregate operation from 3 other aggregate operations.
|
static <T,A1,A2,R1,R2,R> |
allOf(AggregateOperation1<? super T,A1,R1> op1,
AggregateOperation1<? super T,A2,R2> op2,
DistributedBiFunction<? super R1,? super R2,R> finishFn)
Returns composite aggregate operation from 2 other aggregate operations.
|
static <T> AllOfAggregationBuilder<T> |
allOfBuilder()
Returns a fluent API builder object that helps you create a composite
of multiple aggregate operations.
|
static <T> AggregateOperation1<T,LongDoubleAccumulator,Double> |
averagingDouble(DistributedToDoubleFunction<? super T> getDoubleValueFn)
Returns an aggregate operation that computes the arithmetic mean of the
double values it obtains by applying getDoubleValueFn to
each item. |
static <T> AggregateOperation1<T,LongLongAccumulator,Double> |
averagingLong(DistributedToLongFunction<? super T> getLongValueFn)
Returns an aggregate operation that computes the arithmetic mean of the
long values it obtains by applying getLongValueFn to
each item. |
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating()
Returns an aggregate operation that concatenates the input items into a
string.
|
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating(CharSequence delimiter)
Returns an aggregate operation that concatenates the input items into a
string with the given
delimiter . |
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns an aggregate operation that concatenates the input items into a
string with the given
delimiter . |
static <T> AggregateOperation1<T,LongAccumulator,Long> |
counting()
Returns an aggregate operation that computes the number of items.
|
static <T,K> AggregateOperation1<T,Map<K,List<T>>,Map<K,List<T>>> |
groupingBy(DistributedFunction<? super T,? extends K> toKeyFn)
Returns an
AggregateOperation1 that accumulates the items into a
HashMap where the key is the result of applying toKeyFn
and the value is a list of the items with that key. |
static <T,K,A,R> AggregateOperation1<T,Map<K,A>,Map<K,R>> |
groupingBy(DistributedFunction<? super T,? extends K> toKeyFn,
AggregateOperation1<? super T,A,R> downstream)
Returns an
AggregateOperation1 that accumulates the items into a
HashMap where the key is the result of applying toKeyFn
and the value is the result of applying the downstream aggregate
operation to the items with that key. |
static <T,K,R,A,M extends Map<K,R>> |
groupingBy(DistributedFunction<? super T,? extends K> toKeyFn,
DistributedSupplier<M> createMapFn,
AggregateOperation1<? super T,A,R> downstream)
Returns an
AggregateOperation1 that accumulates the items into a
Map (as obtained from createMapFn ) where the key is the
result of applying toKeyFn and the value is the result of
applying the downstream aggregate operation to the items with that key. |
static <T> AggregateOperation1<T,LinTrendAccumulator,Double> |
linearTrend(DistributedToLongFunction<T> getXFn,
DistributedToLongFunction<T> getYFn)
Returns an aggregate operation that computes a linear trend on the items.
|
static <T,U,A,R> AggregateOperation1<T,A,R> |
mapping(DistributedFunction<? super T,? extends U> mapFn,
AggregateOperation1<? super U,A,R> downstream)
Adapts an aggregate operation accepting items of type
U to one accepting items of type T by applying a mapping
function to each item before accumulation. |
static <T> AggregateOperation1<T,MutableReference<T>,T> |
maxBy(DistributedComparator<? super T> comparator)
Returns an aggregate operation that computes the maximal item according
to the given
comparator . |
static <T> AggregateOperation1<T,MutableReference<T>,T> |
minBy(DistributedComparator<? super T> comparator)
Returns an aggregate operation that computes the minimal item according
to the given
comparator . |
static <T,A> AggregateOperation1<T,MutableReference<A>,A> |
reducing(A emptyAccValue,
DistributedFunction<? super T,? extends A> toAccValueFn,
DistributedBinaryOperator<A> combineAccValuesFn,
DistributedBinaryOperator<A> deductAccValueFn)
A reducing operation maintains an accumulated value that starts out as
emptyAccValue and is iteratively transformed by applying
combineAccValuesFn to it and each stream item's accumulated
value, as returned from toAccValueFn . |
static <T> AggregateOperation1<T,DoubleAccumulator,Double> |
summingDouble(DistributedToDoubleFunction<? super T> getDoubleValueFn)
Returns an aggregate operation that computes the sum of the
double
values it obtains by applying getDoubleValueFn to each item. |
static <T> AggregateOperation1<T,LongAccumulator,Long> |
summingLong(DistributedToLongFunction<? super T> getLongValueFn)
Returns an aggregate operation that computes the sum of the
long
values it obtains by applying getLongValueFn to each item. |
static AggregateOperation<BagsByTag,BagsByTag> |
toBagsByTag(Tag<?>... tags)
Returns an
AggregateOperation that accumulates the items from
any number of inputs into BagsByTag : items from inputN
are accumulated into under tagN. |
static <T,C extends Collection<T>> |
toCollection(DistributedSupplier<C> createCollectionFn)
Returns an aggregate operation that accumulates the items into a
Collection . |
static <T> AggregateOperation1<T,List<T>,List<T>> |
toList()
Returns an aggregate operation that accumulates the items into an
ArrayList . |
static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> toKeyFn,
DistributedFunction<? super T,? extends U> toValueFn)
Returns an aggregate operation that accumulates the items into a
HashMap whose keys and values are the result of applying
the provided mapping functions. |
static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> toKeyFn,
DistributedFunction<? super T,? extends U> toValueFn,
DistributedBinaryOperator<U> mergeFn)
Returns an aggregate operation that accumulates the items into a
HashMap whose keys and values are the result of applying
the provided mapping functions. |
static <T,K,U,M extends Map<K,U>> |
toMap(DistributedFunction<? super T,? extends K> toKeyFn,
DistributedFunction<? super T,? extends U> toValueFn,
DistributedBinaryOperator<U> mergeFn,
DistributedSupplier<M> createMapFn)
Returns an
AggregateOperation1 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> AggregateOperation1<T,Set<T>,Set<T>> |
toSet()
Returns an aggregate operation that accumulates the items into a
HashSet . |
static <T0,T1,T2> AggregateOperation3<T0,T1,T2,ThreeBags<T0,T1,T2>,ThreeBags<T0,T1,T2>> |
toThreeBags()
Returns an
AggregateOperation that accumulates the items from
exactly three inputs into ThreeBags : items from inputN
are accumulated into bagN. |
static <T0,T1> AggregateOperation2<T0,T1,TwoBags<T0,T1>,TwoBags<T0,T1>> |
toTwoBags()
Returns an
AggregateOperation that accumulates the items from
exactly two inputs into TwoBags : items from inputN are
accumulated into bagN. |
@Nonnull public static <T> AggregateOperation1<T,LongAccumulator,Long> counting()
@Nonnull public static <T> AggregateOperation1<T,LongAccumulator,Long> summingLong(@Nonnull DistributedToLongFunction<? super T> getLongValueFn)
long
values it obtains by applying getLongValueFn
to each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,DoubleAccumulator,Double> summingDouble(@Nonnull DistributedToDoubleFunction<? super T> getDoubleValueFn)
double
values it obtains by applying getDoubleValueFn
to each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,MutableReference<T>,T> minBy(@Nonnull DistributedComparator<? super T> comparator)
comparator
.
This aggregate operation does not implement the deduct
primitive.
T
- input item type@Nonnull public static <T> AggregateOperation1<T,MutableReference<T>,T> maxBy(@Nonnull DistributedComparator<? super T> comparator)
comparator
.
This aggregate operation does not implement the deduct
primitive.
T
- input item type@Nonnull public static <T> AggregateOperation1<T,LongLongAccumulator,Double> averagingLong(@Nonnull DistributedToLongFunction<? super T> getLongValueFn)
long
values it obtains by applying getLongValueFn
to
each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,LongDoubleAccumulator,Double> averagingDouble(@Nonnull DistributedToDoubleFunction<? super T> getDoubleValueFn)
double
values it obtains by applying getDoubleValueFn
to
each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,LinTrendAccumulator,Double> linearTrend(@Nonnull DistributedToLongFunction<T> getXFn, @Nonnull DistributedToLongFunction<T> getYFn)
double
-valued coefficient that
approximates the rate of change of y
as a function of x
,
where x
and y
are long
quantities obtained
by applying the two provided functions to each item.@Nonnull public static <T,A1,A2,R1,R2> AggregateOperation1<T,Tuple2<A1,A2>,Tuple2<R1,R2>> allOf(@Nonnull AggregateOperation1<? super T,A1,R1> op1, @Nonnull AggregateOperation1<? super T,A2,R2> op2)
allOf(AggregateOperation1, AggregateOperation1,
DistributedBiFunction)
with identity finish.@Nonnull public static <T,A1,A2,R1,R2,R> AggregateOperation1<T,Tuple2<A1,A2>,R> allOf(@Nonnull AggregateOperation1<? super T,A1,R1> op1, @Nonnull AggregateOperation1<? super T,A2,R2> op2, @Nonnull DistributedBiFunction<? super R1,? super R2,R> finishFn)
T
- type of input itemsA1
- 1st accumulator typeA2
- 2nd accumulator typeR1
- 1st result typeR2
- 2nd result typeR
- final result typeop1
- 1st operationop2
- 2nd operationfinishFn
- a function combining 2 results into single target instance@Nonnull public static <T,A1,A2,A3,R1,R2,R3> AggregateOperation1<T,Tuple3<A1,A2,A3>,Tuple3<R1,R2,R3>> allOf(@Nonnull AggregateOperation1<? super T,A1,R1> op1, @Nonnull AggregateOperation1<? super T,A2,R2> op2, @Nonnull AggregateOperation1<? super T,A3,R3> op3)
allOf(AggregateOperation1, AggregateOperation1,
AggregateOperation1, DistributedTriFunction)
with identity finisher.@Nonnull public static <T,A1,A2,A3,R1,R2,R3,R> AggregateOperation1<T,Tuple3<A1,A2,A3>,R> allOf(@Nonnull AggregateOperation1<? super T,A1,R1> op1, @Nonnull AggregateOperation1<? super T,A2,R2> op2, @Nonnull AggregateOperation1<? super T,A3,R3> op3, @Nonnull DistributedTriFunction<? super R1,? super R2,? super R3,R> finishFn)
T
- type of input itemsA1
- 1st accumulator typeA2
- 2nd accumulator typeA3
- 3rd accumulator typeR1
- 1st result typeR2
- 2nd result typeR3
- 3rd result typeR
- final result typeop1
- 1st operationop2
- 2nd operationop3
- 3rd operationfinishFn
- a function combining 3 results into single target instance@Nonnull public static <T> AllOfAggregationBuilder<T> allOfBuilder()
ItemsByTag
object you'll get in the output.
The builder object is primarily intended to build a composite of four or more
aggregate operations. For up to three operations, prefer the explicit, more
type-safe variants allOf(op1, op2)
and allOf(op1, op2, op3)
.
Example that calculates the count and the sum of the items:
AllOfAggregationBuilder<Long> builder = allOfBuilder();
Tag<Long> tagSum = builder.add(summingLong(Long::longValue));
Tag<Long> tagCount = builder.add(counting());
AggregateOperation1<Long, ?, ItemsByTag> compositeAggrOp = builder.build();
When you receive the resulting ItemsByTag
, fetch the individual results using the tags as keys, for example:
batchStage.aggregate(compositeAggrOp).map((ItemsByTag result) -> {
Long sum = result.get(tagSum);
Long count = result.get(tagCount);
...
});
T
- type of input itemspublic static AggregateOperation1<CharSequence,StringBuilder,String> concatenating()
public static AggregateOperation1<CharSequence,StringBuilder,String> concatenating(CharSequence delimiter)
delimiter
.public static AggregateOperation1<CharSequence,StringBuilder,String> concatenating(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
delimiter
. The resulting string will also
have the given prefix
and suffix
.public static <T,U,A,R> AggregateOperation1<T,A,R> mapping(@Nonnull DistributedFunction<? super T,? extends U> mapFn, @Nonnull AggregateOperation1<? super U,A,R> downstream)
U
to one accepting items of type T
by applying a mapping
function to each item before accumulation.
If the mapFn
returns null
, the item won't be aggregated
at all. This allows applying a filter at the same time.
T
- input item typeU
- input type of the downstream aggregate operationA
- downstream operation's accumulator typeR
- downstream operation's result typemapFn
- the function to apply to input itemsdownstream
- the downstream aggregate operationpublic static <T,C extends Collection<T>> AggregateOperation1<T,C,C> toCollection(DistributedSupplier<C> createCollectionFn)
Collection
. It creates the collections as needed by calling the
provided createCollectionFn
.
If you use a collection that preserves the insertion order, keep in mind that there is no specified order in which the items are aggregated.
T
- input item typeC
- the type of the collectioncreateCollectionFn
- a Supplier
which returns a new, empty Collection
of the
appropriate typepublic static <T> AggregateOperation1<T,List<T>,List<T>> toList()
ArrayList
.T
- input item typepublic static <T> AggregateOperation1<T,Set<T>,Set<T>> toSet()
HashSet
.T
- input item typepublic static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> toMap(DistributedFunction<? super T,? extends K> toKeyFn, DistributedFunction<? super T,? extends U> toValueFn)
HashMap
whose keys and values are the result of applying
the provided mapping functions.
This aggregate operation does not tolerate duplicate keys and will
throw IllegalStateException
if it detects them. If your
data contains duplicates, use the toMap()
overload
that can resolve them.
T
- input item typeK
- type of the keyU
- type of the valuetoKeyFn
- a function to extract the key from the input itemtoValueFn
- a function to extract the value from the input itemtoMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator, DistributedSupplier)
public static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> toMap(DistributedFunction<? super T,? extends K> toKeyFn, DistributedFunction<? super T,? extends U> toValueFn, DistributedBinaryOperator<U> mergeFn)
HashMap
whose keys and values are the result of applying
the provided mapping functions.
This aggregate operation resolves duplicate keys by applying mergeFn
to the conflicting values. mergeFn
will act upon the
values after toValueFn
has already been applied.
T
- input item typeK
- the type of keyU
- the output type of the value mapping functiontoKeyFn
- a function to extract the key from input itemtoValueFn
- a function to extract value from input itemmergeFn
- 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)
toMap(DistributedFunction, DistributedFunction)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator, DistributedSupplier)
public static <T,K,U,M extends Map<K,U>> AggregateOperation1<T,M,M> toMap(DistributedFunction<? super T,? extends K> toKeyFn, DistributedFunction<? super T,? extends U> toValueFn, DistributedBinaryOperator<U> mergeFn, DistributedSupplier<M> createMapFn)
AggregateOperation1
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 contain 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 createMapFn
function.
T
- input item typeK
- the output type of the key mapping functionU
- the output type of the value mapping functionM
- the type of the resulting Map
toKeyFn
- a function to extract the key from input itemtoValueFn
- a function to extract value from input itemmergeFn
- 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)
createMapFn
- a function which returns a new, empty Map
into
which the results will be insertedtoMap(DistributedFunction, DistributedFunction)
,
toMap(DistributedFunction, DistributedFunction, DistributedBinaryOperator)
@Nonnull public static <T0,T1> AggregateOperation2<T0,T1,TwoBags<T0,T1>,TwoBags<T0,T1>> toTwoBags()
AggregateOperation
that accumulates the items from
exactly two inputs into TwoBags
: items from inputN are
accumulated into bagN.T0
- item type on input0T1
- item type on input1toThreeBags()
,
toBagsByTag(Tag[])
@Nonnull public static <T0,T1,T2> AggregateOperation3<T0,T1,T2,ThreeBags<T0,T1,T2>,ThreeBags<T0,T1,T2>> toThreeBags()
AggregateOperation
that accumulates the items from
exactly three inputs into ThreeBags
: items from inputN
are accumulated into bagN.T0
- item type on input0T1
- item type on input1T2
- item type on input2toTwoBags()
,
toBagsByTag(Tag[])
@Nonnull public static AggregateOperation<BagsByTag,BagsByTag> toBagsByTag(@Nonnull Tag<?>... tags)
AggregateOperation
that accumulates the items from
any number of inputs into BagsByTag
: items from inputN
are accumulated into under tagN.toTwoBags()
,
toThreeBags()
public static <T,K> AggregateOperation1<T,Map<K,List<T>>,Map<K,List<T>>> groupingBy(DistributedFunction<? super T,? extends K> toKeyFn)
AggregateOperation1
that accumulates the items into a
HashMap
where the key is the result of applying toKeyFn
and the value is a list of the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functiontoKeyFn
- a function to extract the key from input itemgroupingBy(DistributedFunction, AggregateOperation1)
,
groupingBy(DistributedFunction, DistributedSupplier, AggregateOperation1)
public static <T,K,A,R> AggregateOperation1<T,Map<K,A>,Map<K,R>> groupingBy(DistributedFunction<? super T,? extends K> toKeyFn, AggregateOperation1<? super T,A,R> downstream)
AggregateOperation1
that accumulates the items into a
HashMap
where the key is the result of applying toKeyFn
and the value is the result of applying the downstream aggregate
operation to the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functionR
- the type of the downstream aggregation resultA
- downstream aggregation's accumulator typetoKeyFn
- a function to extract the key from input itemdownstream
- the downstream aggregate operationgroupingBy(DistributedFunction)
,
groupingBy(DistributedFunction, DistributedSupplier, AggregateOperation1)
public static <T,K,R,A,M extends Map<K,R>> AggregateOperation1<T,Map<K,A>,M> groupingBy(DistributedFunction<? super T,? extends K> toKeyFn, DistributedSupplier<M> createMapFn, AggregateOperation1<? super T,A,R> downstream)
AggregateOperation1
that accumulates the items into a
Map
(as obtained from createMapFn
) where the key is the
result of applying toKeyFn
and the value is the result of
applying the downstream aggregate operation to the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functionR
- the type of the downstream aggregation resultA
- downstream aggregation's accumulator typeM
- output type of the resulting Map
toKeyFn
- a function to extract the key from input itemcreateMapFn
- a function which returns a new, empty Map
into
which the results will be inserteddownstream
- the downstream aggregate operationgroupingBy(DistributedFunction)
,
groupingBy(DistributedFunction, AggregateOperation1)
@Nonnull public static <T,A> AggregateOperation1<T,MutableReference<A>,A> reducing(@Nonnull A emptyAccValue, @Nonnull DistributedFunction<? super T,? extends A> toAccValueFn, @Nonnull DistributedBinaryOperator<A> combineAccValuesFn, @Nullable DistributedBinaryOperator<A> deductAccValueFn)
emptyAccValue
and is iteratively transformed by applying
combineAccValuesFn
to it and each stream item's accumulated
value, as returned from toAccValueFn
. combineAccValuesFn
must be associative because it will also be used to combine
partial results, as well as commutative because the encounter
order of items is unspecified.
The optional deductAccValueFn
allows Jet to compute the sliding
window in O(1) time. It must undo the effects of a previous combineAccValuesFn
call:
A accVal; (has some pre-existing value) A itemAccVal = toAccValueFn.apply(item); A combined = combineAccValuesFn.apply(accVal, itemAccVal); A deducted = deductAccValueFn.apply(combined, itemAccVal); assert deducted.equals(accVal);
T
- input item typeA
- type of the accumulated valueemptyAccValue
- the reducing operation's emptyAccValue elementtoAccValueFn
- transforms the stream item into its accumulated valuecombineAccValuesFn
- combines two accumulated values into onedeductAccValueFn
- deducts the right-hand accumulated value from the left-hand one
(optional)Copyright © 2018 Hazelcast, Inc.. All rights reserved.