A - the mutable accumulation type of the reduction operation (often
hidden as an implementation detail)R - the result type of the reduction operationpublic interface LongCollector<A,R>
Collector specialized to work with primitive long.LongStreamEx.collect(LongCollector)Collector.Characteristics| Modifier and Type | Method and Description |
|---|---|
default BiConsumer<A,Long> |
accumulator()
A function that folds a value into a mutable result container.
|
default <RR> LongCollector<A,RR> |
andThen(Function<R,RR> finisher)
Adapts this collector to perform an additional finishing transformation.
|
static LongCollector<?,OptionalDouble> |
averaging()
Returns a
LongCollector that produces the arithmetic mean of the
input elements or an empty optional if no elements are collected. |
default BinaryOperator<A> |
combiner()
A function that accepts two partial results and combines them returning
either existing partial result or new one.
|
static LongCollector<?,Long> |
counting()
Returns a
LongCollector that counts the number of input elements
and returns the result as Long. |
static LongCollector<?,Integer> |
countingInt()
Returns an
LongCollector that counts the number of input elements
and returns the result as Integer. |
static <K> LongCollector<?,Map<K,long[]>> |
groupingBy(LongFunction<? extends K> classifier)
Returns a
LongCollector implementing a "group by" operation on
input numbers, grouping them according to a classification function, and
returning the results in a Map. |
static <K,D,A> LongCollector<?,Map<K,D>> |
groupingBy(LongFunction<? extends K> classifier,
LongCollector<A,D> downstream)
Returns a
LongCollector implementing a cascaded "group by"
operation on input numbers, grouping them according to a classification
function, and then performing a reduction operation on the values
associated with a given key using the specified downstream
IntCollector. |
static <K,D,A,M extends Map<K,D>> |
groupingBy(LongFunction<? extends K> classifier,
Supplier<M> mapFactory,
LongCollector<A,D> downstream)
Returns a
LongCollector implementing a cascaded "group by"
operation on input numbers, grouping them according to a classification
function, and then performing a reduction operation on the values
associated with a given key using the specified downstream
IntCollector. |
static LongCollector<?,String> |
joining(CharSequence delimiter)
Returns a
LongCollector that converts the input numbers to
strings and concatenates them, separated by the specified delimiter, in
encounter order. |
static LongCollector<?,String> |
joining(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns a
LongCollector that converts the input numbers to
strings and concatenates them, separated by the specified delimiter, with
the specified prefix and suffix, in encounter order. |
ObjLongConsumer<A> |
longAccumulator()
A function that folds a value into a mutable result container.
|
static <A,R> LongCollector<?,R> |
mapping(LongUnaryOperator mapper,
LongCollector<A,R> downstream)
Adapts a
LongCollector to another one by applying a mapping
function to each input element before accumulation. |
static <U,A,R> LongCollector<?,R> |
mappingToObj(LongFunction<U> mapper,
Collector<U,A,R> downstream)
Adapts a
Collector accepting elements of type U to a
LongCollector by applying a mapping function to each input
element before accumulation. |
static LongCollector<?,OptionalLong> |
max()
Returns a
LongCollector that produces the maximal element,
described as an OptionalLong. |
BiConsumer<A,A> |
merger()
A function that merges the second partial result into the first partial
result.
|
static LongCollector<?,OptionalLong> |
min()
Returns a
LongCollector that produces the minimal element,
described as an OptionalLong. |
static <A,R> LongCollector<?,R> |
of(Collector<Long,A,R> collector)
Adapts a
Collector which accepts elements of type Long to
a LongCollector. |
static <A,R> LongCollector<A,R> |
of(Supplier<A> supplier,
ObjLongConsumer<A> longAccumulator,
BiConsumer<A,A> merger,
Function<A,R> finisher)
Returns a new
LongCollector described by the given
supplier, accumulator, merger, and
finisher functions. |
static <R> LongCollector<R,R> |
of(Supplier<R> supplier,
ObjLongConsumer<R> longAccumulator,
BiConsumer<R,R> merger)
Returns a new
LongCollector described by the given
supplier, accumulator, and merger functions. |
static LongCollector<?,Map<Boolean,long[]>> |
partitioningBy(LongPredicate predicate)
Returns a
LongCollector which partitions the input elements
according to a LongPredicate, and organizes them into a
Map<Boolean, long[]>. |
static <A,D> LongCollector<?,Map<Boolean,D>> |
partitioningBy(LongPredicate predicate,
LongCollector<A,D> downstream)
Returns a
LongCollector which partitions the input numbers
according to a LongPredicate, reduces the values in each
partition according to another IntCollector, and organizes them
into a Map<Boolean, D> whose values are the result of the
downstream reduction. |
static LongCollector<?,OptionalLong> |
reducing(LongBinaryOperator op)
Returns a
LongCollector which performs a reduction of its input
numbers under a specified LongBinaryOperator. |
static LongCollector<?,Long> |
reducing(long identity,
LongBinaryOperator op)
Returns a
LongCollector which performs a reduction of its input
numbers under a specified IntBinaryOperator using the provided
identity. |
static LongCollector<?,LongSummaryStatistics> |
summarizing()
Returns a
LongCollector which returns summary statistics for the
input elements. |
static LongCollector<?,Long> |
summing()
Returns a
LongCollector that produces the sum of the input
elements. |
static LongCollector<?,long[]> |
toArray()
Returns a
LongCollector that produces the array of the input
elements. |
static LongCollector<?,boolean[]> |
toBooleanArray(LongPredicate predicate)
Returns a
LongCollector which produces a boolean array containing
the results of applying the given predicate to the input elements, in
encounter order. |
ObjLongConsumer<A> longAccumulator()
default BiConsumer<A,Long> accumulator()
longAccumulator() on unboxed
value.default <RR> LongCollector<A,RR> andThen(Function<R,RR> finisher)
RR - result type of the resulting collectorfinisher - a function to be applied to the final result of this
collectorstatic <R> LongCollector<R,R> of(Supplier<R> supplier, ObjLongConsumer<R> longAccumulator, BiConsumer<R,R> merger)
LongCollector described by the given
supplier, accumulator, and merger functions. The
resulting LongCollector has the
Collector.Characteristics.IDENTITY_FINISH characteristic.R - The type of intermediate accumulation result, and final
result, for the new collectorsupplier - The supplier function for the new collectorlongAccumulator - The longAccumulator function for the new collectormerger - The merger function for the new collectorLongCollectorstatic <A,R> LongCollector<?,R> of(Collector<Long,A,R> collector)
Collector which accepts elements of type Long to
a LongCollector.A - The intermediate accumulation type of the collectorR - The final result type of the collectorcollector - a Collector to adaptLongCollector which behaves in the same way as input
collector.static <A,R> LongCollector<A,R> of(Supplier<A> supplier, ObjLongConsumer<A> longAccumulator, BiConsumer<A,A> merger, Function<A,R> finisher)
LongCollector described by the given
supplier, accumulator, merger, and
finisher functions.A - The intermediate accumulation type of the new collectorR - The final result type of the new collectorsupplier - The supplier function for the new collectorlongAccumulator - The longAccumulator function for the new collectormerger - The merger function for the new collectorfinisher - The finisher function for the new collectorLongCollectorstatic LongCollector<?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
LongCollector that converts the input numbers to
strings and concatenates them, 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 resultLongCollector which concatenates the input numbers,
separated by the specified delimiter, in encounter orderstatic LongCollector<?,String> joining(CharSequence delimiter)
LongCollector that converts the input numbers to
strings and concatenates them, separated by the specified delimiter, in
encounter order.delimiter - the delimiter to be used between each elementLongCollector which concatenates the input numbers,
separated by the specified delimiter, in encounter orderstatic LongCollector<?,Long> counting()
LongCollector that counts the number of input elements
and returns the result as Long. If no elements are present, the
result is 0.LongCollector that counts the input elementsstatic LongCollector<?,Integer> countingInt()
LongCollector that counts the number of input elements
and returns the result as Integer. If no elements are present,
the result is 0.LongCollector that counts the input elementsstatic LongCollector<?,Long> summing()
LongCollector that produces the sum of the input
elements. If no elements are present, the result is 0.LongCollector that produces the sum of the input
elementsstatic LongCollector<?,OptionalDouble> averaging()
LongCollector that produces the arithmetic mean of the
input elements or an empty optional if no elements are collected.
Note that unlike LongStream.average(),
Collectors.averagingLong(java.util.function.ToLongFunction) and
LongSummaryStatistics.getAverage() this collector does not
overflow if an intermediate sum exceeds Long.MAX_VALUE.
LongCollector that produces the arithmetic mean of the
input elementsstatic LongCollector<?,OptionalLong> min()
LongCollector that produces the minimal element,
described as an OptionalLong. If no elements are present, the
result is an empty OptionalLong.LongCollector that produces the minimal element.static LongCollector<?,OptionalLong> max()
LongCollector that produces the maximal element,
described as an OptionalLong. If no elements are present, the
result is an empty OptionalLong.LongCollector that produces the maximal element.static <A,R> LongCollector<?,R> mapping(LongUnaryOperator mapper, LongCollector<A,R> downstream)
LongCollector to another one by applying a mapping
function to each input element before accumulation.A - 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 valuesstatic <U,A,R> LongCollector<?,R> mappingToObj(LongFunction<U> mapper, Collector<U,A,R> downstream)
Collector accepting elements of type U to a
LongCollector by applying a mapping function to each input
element before accumulation.U - 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 valuesstatic LongCollector<?,OptionalLong> reducing(LongBinaryOperator op)
LongCollector which performs a reduction of its input
numbers under a specified LongBinaryOperator. The result is
described as an OptionalLong.op - a LongBinaryOperator used to reduce the input numbersLongCollector which implements the reduction operation.static LongCollector<?,Long> reducing(long identity, LongBinaryOperator op)
LongCollector which performs a reduction of its input
numbers under a specified IntBinaryOperator using the provided
identity.identity - the identity value for the reduction (also, the value
that is returned when there are no input elements)op - a LongBinaryOperator used to reduce the input numbersLongCollector which implements the reduction operationstatic LongCollector<?,LongSummaryStatistics> summarizing()
LongCollector which returns summary statistics for the
input elements.LongCollector implementing the summary-statistics
reductionstatic LongCollector<?,Map<Boolean,long[]>> partitioningBy(LongPredicate predicate)
LongCollector which partitions the input elements
according to a LongPredicate, and organizes them into a
Map<Boolean, long[]>.
There are no guarantees on the type, mutability, serializability, or
thread-safety of the Map returned.predicate - a predicate used for classifying input elementsLongCollector implementing the partitioning operationstatic <A,D> LongCollector<?,Map<Boolean,D>> partitioningBy(LongPredicate predicate, LongCollector<A,D> downstream)
LongCollector which partitions the input numbers
according to a LongPredicate, reduces the values in each
partition according to another IntCollector, 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.
A - the intermediate accumulation type of the downstream collectorD - the result type of the downstream reductionpredicate - a predicate used for classifying input elementsdownstream - a LongCollector implementing the downstream
reductionLongCollector implementing the cascaded partitioning
operationstatic <K> LongCollector<?,Map<K,long[]>> groupingBy(LongFunction<? extends K> classifier)
LongCollector implementing a "group by" operation on
input numbers, grouping them 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, long[]> whose keys are the values
resulting from applying the classification function to the input numbers,
and whose corresponding values are arrays containing the input numbers
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 objects returned.
K - the type of the keysclassifier - the classifier function mapping input elements to keysLongCollector implementing the group-by operationstatic <K,D,A> LongCollector<?,Map<K,D>> groupingBy(LongFunction<? extends K> classifier, LongCollector<A,D> downstream)
LongCollector implementing a cascaded "group by"
operation on input numbers, grouping them according to a classification
function, and then performing a reduction operation on the values
associated with a given key using the specified downstream
IntCollector.
The classification function maps elements to some key type K. The
downstream collector 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.
K - 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 LongCollector implementing the downstream
reductionLongCollector implementing the cascaded group-by
operationstatic <K,D,A,M extends Map<K,D>> LongCollector<?,M> groupingBy(LongFunction<? extends K> classifier, Supplier<M> mapFactory, LongCollector<A,D> downstream)
LongCollector implementing a cascaded "group by"
operation on input numbers, grouping them according to a classification
function, and then performing a reduction operation on the values
associated with a given key using the specified downstream
IntCollector. 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 produces a result of type D. The resulting
collector produces a Map<K, D>.
K - 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 Mapclassifier - a classifier function mapping input elements to keysdownstream - a LongCollector implementing the downstream
reductionmapFactory - a function which, when called, produces a new empty
Map of the desired typeLongCollector implementing the cascaded group-by
operationstatic LongCollector<?,long[]> toArray()
LongCollector that produces the array of the input
elements. If no elements are present, the result is an empty array.LongCollector that produces the array of the input
elementsstatic LongCollector<?,boolean[]> toBooleanArray(LongPredicate predicate)
LongCollector which produces a boolean array containing
the results of applying the given predicate to the input elements, in
encounter order.predicate - a non-interfering, stateless predicate to apply to each
input element. The result values of this predicate are collected
to the resulting boolean array.LongCollector which collects the results of the
predicate function to the boolean array, in encounter order.BiConsumer<A,A> merger()
default BinaryOperator<A> combiner()
merger() and returns the
first partial result.Copyright © 2017. All rights reserved.