public final class Collectors
extends java.lang.Object
Collector interface.Collector| Modifier and Type | Method and Description |
|---|---|
static <T> Collector<T,?,java.lang.Double> |
averaging(Function<? super T,java.lang.Double> mapper)
Deprecated.
As of release 1.1.3, replaced by
averagingDouble(com.annimon.stream.function.ToDoubleFunction) |
static <T> Collector<T,?,java.lang.Double> |
averagingDouble(ToDoubleFunction<? super T> mapper)
Returns a
Collector that calculates average of double-valued input elements. |
static <T> Collector<T,?,java.lang.Double> |
averagingInt(ToIntFunction<? super T> mapper)
Returns a
Collector that calculates average of integer-valued input elements. |
static <T> Collector<T,?,java.lang.Double> |
averagingLong(ToLongFunction<? super T> mapper)
Returns a
Collector that calculates average of long-valued input elements. |
static <T,A,IR,OR> |
collectingAndThen(Collector<T,A,IR> c,
Function<IR,OR> finisher)
Returns a
Collector that performs additional transformation. |
static <T> Collector<T,?,java.lang.Long> |
counting()
Returns a
Collector that counts the number of input elements. |
static <T,A,R> Collector<T,?,R> |
filtering(Predicate<? super T> predicate,
Collector<? super T,A,R> downstream)
Returns a
Collector that filters input elements. |
static <T,U,A,R> Collector<T,?,R> |
flatMapping(Function<? super T,? extends Stream<? extends U>> mapper,
Collector<? super U,A,R> downstream)
Returns a
Collector that performs flat-mapping before accumulation. |
static <T,K> Collector<T,?,java.util.Map<K,java.util.List<T>>> |
groupingBy(Function<? super T,? extends K> classifier)
Returns a
Collector that performs grouping operation by given classifier. |
static <T,K,A,D> Collector<T,?,java.util.Map<K,D>> |
groupingBy(Function<? super T,? extends K> classifier,
Collector<? super T,A,D> downstream)
Returns a
Collector that performs grouping operation by given classifier. |
static <T,K,D,A,M extends java.util.Map<K,D>> |
groupingBy(Function<? super T,? extends K> classifier,
Supplier<M> mapFactory,
Collector<? super T,A,D> downstream)
Returns a
Collector that performs grouping operation by given classifier. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining()
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter)
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix,
java.lang.String emptyValue)
Returns a
Collector that concatenates input elements into new string. |
static <T,U,A,R> Collector<T,?,R> |
mapping(Function<? super T,? extends U> mapper,
Collector<? super U,A,R> downstream)
Returns a
Collector that performs mapping before accumulation. |
static <T> Collector<T,?,java.util.Map<java.lang.Boolean,java.util.List<T>>> |
partitioningBy(Predicate<? super T> predicate)
Returns a
Collector that performs partitioning operation according to a predicate. |
static <T,D,A> Collector<T,?,java.util.Map<java.lang.Boolean,D>> |
partitioningBy(Predicate<? super T> predicate,
Collector<? super T,A,D> downstream)
Returns a
Collector that performs partitioning operation according to a predicate. |
static <T,R> Collector<T,?,R> |
reducing(R identity,
Function<? super T,? extends R> mapper,
BinaryOperator<R> op)
Returns a
Collector that reduces input elements. |
static <T> Collector<T,?,T> |
reducing(T identity,
BinaryOperator<T> op)
Returns a
Collector that reduces input elements. |
static <T> Collector<T,?,java.lang.Double> |
summingDouble(ToDoubleFunction<? super T> mapper)
Returns a
Collector that summing double-valued input elements. |
static <T> Collector<T,?,java.lang.Integer> |
summingInt(ToIntFunction<? super T> mapper)
Returns a
Collector that summing integer-valued input elements. |
static <T> Collector<T,?,java.lang.Long> |
summingLong(ToLongFunction<? super T> mapper)
Returns a
Collector that summing long-valued input elements. |
static <T,R1,R2,R> |
teeing(Collector<? super T,?,R1> downstream1,
Collector<? super T,?,R2> downstream2,
BiFunction<? super R1,? super R2,R> merger)
Returns a
Collector that composites two collectors. |
static <T,R extends java.util.Collection<T>> |
toCollection(Supplier<R> collectionSupplier)
Returns a
Collector that fills new Collection, provided by collectionSupplier,
with input elements. |
static <T> Collector<T,?,java.util.List<T>> |
toList()
Returns a
Collector that fills new List with input elements. |
static <T,K> Collector<T,?,java.util.Map<K,T>> |
toMap(Function<? super T,? extends K> keyMapper)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
BinaryOperator<V> mergeFunction)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
BinaryOperator<V> mergeFunction,
Supplier<M> mapFactory)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
Supplier<M> mapFactory)
Returns a
Collector that fills new Map with input elements. |
static <T> Collector<T,?,java.util.Set<T>> |
toSet()
Returns a
Collector that fills new Set with input elements. |
static <T> Collector<T,?,java.util.List<T>> |
toUnmodifiableList()
Returns a
Collector that fills new unmodifiable List with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toUnmodifiableMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
Returns a
Collector that fills new unmodifiable Map with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toUnmodifiableMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
BinaryOperator<V> mergeFunction)
Returns a
Collector that fills new unmodifiable Map with input elements. |
static <T> Collector<T,?,java.util.Set<T>> |
toUnmodifiableSet()
Returns a
Collector that fills new unmodifiable Set with input elements. |
@NotNull public static <T,R extends java.util.Collection<T>> Collector<T,?,R> toCollection(@NotNull Supplier<R> collectionSupplier)
Collector that fills new Collection, provided by collectionSupplier,
with input elements.T - the type of the input elementsR - the type of the resulting collectioncollectionSupplier - a supplier function that provides new collectionCollector@NotNull public static <T> Collector<T,?,java.util.List<T>> toList()
Collector that fills new List with input elements.T - the type of the input elementsCollector@NotNull public static <T> Collector<T,?,java.util.List<T>> toUnmodifiableList()
Collector that fills new unmodifiable List with input elements.
The returned Collector disallows nulls
and throws NullPointerException if it is presented with a null value.T - the type of the input elementsCollector@NotNull public static <T> Collector<T,?,java.util.Set<T>> toSet()
Collector that fills new Set with input elements.T - the type of the input elementsCollector@NotNull public static <T> Collector<T,?,java.util.Set<T>> toUnmodifiableSet()
Collector that fills new unmodifiable Set with input elements.
The returned Collector disallows nulls
and throws NullPointerException if it is presented with a null value.
If elements contain duplicates, an arbitrary element of the duplicates is preserved.T - the type of the input elementsCollector@NotNull public static <T,K> Collector<T,?,java.util.Map<K,T>> toMap(@NotNull Function<? super T,? extends K> keyMapper)
Collector that fills new Map with input elements.
If the mapped keys contain duplicates, an IllegalStateException is thrown.
Use toMap(Function, Function, BinaryOperator) to handle merging of the values.T - the type of the input elements and the result type of value mapping functionK - the result type of key mapping functionkeyMapper - a mapping function to produce keysCollectortoMap(Function, Function, BinaryOperator)@NotNull public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper)
Collector that fills new Map with input elements.
If the mapped keys contain duplicates, an IllegalStateException is thrown.
Use toMap(Function, Function, BinaryOperator) to handle merging of the values.T - the type of the input elementsK - the result type of key mapping functionV - the result type of value mapping functionkeyMapper - a mapping function to produce keysvalueMapper - a mapping function to produce valuesCollectortoMap(Function, Function, BinaryOperator)@NotNull public static <T,K,V,M extends java.util.Map<K,V>> Collector<T,?,M> toMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper, @NotNull Supplier<M> mapFactory)
Collector that fills new Map with input elements.
If the mapped keys contain duplicates, an IllegalStateException is thrown.
Use toMap(Function, Function, BinaryOperator, Supplier) to handle merging of the values.T - the type of the input elementsK - the result type of key mapping functionV - the result type of value mapping functionM - the type of the resulting MapkeyMapper - a mapping function to produce keysvalueMapper - a mapping function to produce valuesmapFactory - a supplier function that provides new MapCollectortoMap(Function, Function, BinaryOperator, Supplier)@NotNull public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toUnmodifiableMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper)
Collector that fills new unmodifiable Map with input elements.
The returned Collector disallows null keys and values.
If the mapped keys contain duplicates, an IllegalStateException is thrown,
see toUnmodifiableMap(Function, Function, BinaryOperator).T - the type of the input elementsK - the result type of key mapping functionV - the result type of value mapping functionkeyMapper - a mapping function to produce keysvalueMapper - a mapping function to produce valuesCollectortoUnmodifiableMap(Function, Function, BinaryOperator)@NotNull public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper, @NotNull BinaryOperator<V> mergeFunction)
Collector that fills new Map with input elements.
If the mapped keys contain duplicates, 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 result type of key mapping functionV - the result type of 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 keyCollector@NotNull public static <T,K,V,M extends java.util.Map<K,V>> Collector<T,?,M> toMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper, @NotNull BinaryOperator<V> mergeFunction, @NotNull Supplier<M> mapFactory)
Collector that fills new Map with input elements.
If the mapped keys contain duplicates, 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 result type of key mapping functionV - the result type of value mapping functionM - the type of the resulting MapkeyMapper - 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 keymapFactory - a supplier function that provides new MapCollector@NotNull public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toUnmodifiableMap(@NotNull Function<? super T,? extends K> keyMapper, @NotNull Function<? super T,? extends V> valueMapper, @NotNull BinaryOperator<V> mergeFunction)
Collector that fills new unmodifiable Map with input elements.
The returned Collector disallows null keys and values.T - the type of the input elementsK - the result type of key mapping functionV - the result type of 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 keyCollector@NotNull public static Collector<java.lang.CharSequence,?,java.lang.String> joining()
Collector that concatenates input elements into new string.Collector@NotNull public static Collector<java.lang.CharSequence,?,java.lang.String> joining(@NotNull java.lang.CharSequence delimiter)
Collector that concatenates input elements into new string.delimiter - the delimiter between each elementCollector@NotNull public static Collector<java.lang.CharSequence,?,java.lang.String> joining(@NotNull java.lang.CharSequence delimiter, @NotNull java.lang.CharSequence prefix, @NotNull java.lang.CharSequence suffix)
Collector that concatenates input elements into new string.delimiter - the delimiter between each elementprefix - the prefix of resultsuffix - the suffix of resultCollector@NotNull public static Collector<java.lang.CharSequence,?,java.lang.String> joining(@NotNull java.lang.CharSequence delimiter, @NotNull java.lang.CharSequence prefix, @NotNull java.lang.CharSequence suffix, @NotNull java.lang.String emptyValue)
Collector that concatenates input elements into new string.delimiter - the delimiter between each elementprefix - the prefix of resultsuffix - the suffix of resultemptyValue - the string which replaces empty element if existsCollector@Deprecated @NotNull public static <T> Collector<T,?,java.lang.Double> averaging(@NotNull Function<? super T,java.lang.Double> mapper)
averagingDouble(com.annimon.stream.function.ToDoubleFunction)Collector that calculates average of input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Double> averagingInt(@NotNull ToIntFunction<? super T> mapper)
Collector that calculates average of integer-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Double> averagingLong(@NotNull ToLongFunction<? super T> mapper)
Collector that calculates average of long-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Double> averagingDouble(@NotNull ToDoubleFunction<? super T> mapper)
Collector that calculates average of double-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Integer> summingInt(@NotNull ToIntFunction<? super T> mapper)
Collector that summing integer-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Long> summingLong(@NotNull ToLongFunction<? super T> mapper)
Collector that summing long-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Double> summingDouble(@NotNull ToDoubleFunction<? super T> mapper)
Collector that summing double-valued input elements.T - the type of the input elementsmapper - the mapping function which extracts value from element to calculate resultCollector@NotNull public static <T> Collector<T,?,java.lang.Long> counting()
Collector that counts the number of input elements.T - the type of the input elementsCollector@NotNull public static <T> Collector<T,?,T> reducing(@Nullable T identity, @NotNull BinaryOperator<T> op)
Collector that reduces input elements.T - the type of the input elementsidentity - the initial valueop - the operator to reduce elementsCollectorreducing(java.lang.Object, com.annimon.stream.function.Function, com.annimon.stream.function.BinaryOperator)@NotNull public static <T,R> Collector<T,?,R> reducing(@Nullable R identity, @NotNull Function<? super T,? extends R> mapper, @NotNull BinaryOperator<R> op)
Collector that reduces input elements.T - the type of the input elementsR - the type of the output elementsidentity - the initial valuemapper - the mapping functionop - the operator to reduce elementsCollectorreducing(java.lang.Object, com.annimon.stream.function.BinaryOperator)@NotNull public static <T,A,R> Collector<T,?,R> filtering(@NotNull Predicate<? super T> predicate, @NotNull Collector<? super T,A,R> downstream)
Collector that filters input elements.T - the type of the input elementsA - the accumulation typeR - the type of the output elementspredicate - a predicate used to filter elementsdownstream - the collector of filtered elementsCollector@NotNull public static <T,U,A,R> Collector<T,?,R> mapping(@NotNull Function<? super T,? extends U> mapper, @NotNull Collector<? super U,A,R> downstream)
Collector that performs mapping before accumulation.T - the type of the input elementsU - the result type of mapping functionA - the accumulation typeR - the result type of collectormapper - a function that performs mapping to input elementsdownstream - the collector of mapped elementsCollector@NotNull public static <T,U,A,R> Collector<T,?,R> flatMapping(@NotNull Function<? super T,? extends Stream<? extends U>> mapper, @NotNull Collector<? super U,A,R> downstream)
Collector that performs flat-mapping before accumulation.T - the type of the input elementsU - the result type of flat-mapping functionA - the accumulation typeR - the result type of collectormapper - a function that performs flat-mapping to input elementsdownstream - the collector of flat-mapped elementsCollector@NotNull public static <T,A,IR,OR> Collector<T,A,OR> collectingAndThen(@NotNull Collector<T,A,IR> c, @NotNull Function<IR,OR> finisher)
Collector that performs additional transformation.T - the type of the input elementsA - the accumulation typeIR - the input type of the transformation functionOR - the output type of the transformation functionc - the input Collectorfinisher - the final transformation functionCollector@NotNull public static <T,K> Collector<T,?,java.util.Map<K,java.util.List<T>>> groupingBy(@NotNull Function<? super T,? extends K> classifier)
Collector that performs grouping operation by given classifier.T - the type of the input elementsK - the type of the keysclassifier - the classifier functionCollectorgroupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector),
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.function.Supplier, com.annimon.stream.Collector)@NotNull public static <T,K,A,D> Collector<T,?,java.util.Map<K,D>> groupingBy(@NotNull Function<? super T,? extends K> classifier, @NotNull Collector<? super T,A,D> downstream)
Collector that performs grouping operation by given classifier.T - the type of the input elementsK - the type of the keysA - the accumulation typeD - the result type of downstream reductionclassifier - the classifier functiondownstream - the collector of mapped elementsCollectorgroupingBy(com.annimon.stream.function.Function),
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.function.Supplier, com.annimon.stream.Collector)@NotNull public static <T,K,D,A,M extends java.util.Map<K,D>> Collector<T,?,M> groupingBy(@NotNull Function<? super T,? extends K> classifier, @NotNull Supplier<M> mapFactory, @NotNull Collector<? super T,A,D> downstream)
Collector that performs grouping operation by given classifier.T - the type of the input elementsK - the type of the keysA - the accumulation typeD - the result type of downstream reductionM - the type of the resulting Mapclassifier - the classifier functionmapFactory - a supplier function that provides new Mapdownstream - the collector of mapped elementsCollectorgroupingBy(com.annimon.stream.function.Function),
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector)@NotNull public static <T> Collector<T,?,java.util.Map<java.lang.Boolean,java.util.List<T>>> partitioningBy(@NotNull Predicate<? super T> predicate)
Collector that performs partitioning operation according to a predicate.
The returned Map always contains mappings for both false and true keys.T - the type of the input elementspredicate - a predicate used for classifying input elementsCollector@NotNull public static <T,D,A> Collector<T,?,java.util.Map<java.lang.Boolean,D>> partitioningBy(@NotNull Predicate<? super T> predicate, @NotNull Collector<? super T,A,D> downstream)
Collector that performs partitioning operation according to a predicate.
The returned Map always contains mappings for both false and true keys.T - the type of the input elementsD - the result type of downstream reductionA - the accumulation typepredicate - a predicate used for classifying input elementsdownstream - the collector of partitioned elementsCollector@NotNull public static <T,R1,R2,R> Collector<T,?,R> teeing(@NotNull Collector<? super T,?,R1> downstream1, @NotNull Collector<? super T,?,R2> downstream2, @NotNull BiFunction<? super R1,? super R2,R> merger)
Collector that composites two collectors.
Each element is processed by two specified collectors,
then their results are merged using the merge function into the final result.T - the type of the input elementsR1 - the result type of the first collectorR2 - the result type of the second collectorR - the type of the final resultdownstream1 - the first collectordownstream2 - the second collectormerger - the function which merges two results into the single oneCollector