Interface IntCollector<A,R>
-
- Type Parameters:
A- the mutable accumulation type of the reduction operation (often hidden as an implementation detail)R- the result type of the reduction operation
public interface IntCollector<A,R>ACollectorspecialized to work with primitiveint.- Since:
- 0.3.0
- Author:
- Tagir Valeev
- See Also:
IntStreamEx.collect(IntCollector)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface Collector
Collector.Characteristics
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default BiConsumer<A,Integer>accumulator()A function that folds a value into a mutable result container.default <RR> IntCollector<A,RR>andThen(Function<R,RR> finisher)Adapts this collector to perform an additional finishing transformation.static IntCollector<?,OptionalDouble>averaging()Returns anIntCollectorthat 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 IntCollector<?,Long>counting()Returns anIntCollectorthat counts the number of input elements and returns the result asLong.static IntCollector<?,Integer>countingInt()Returns anIntCollectorthat counts the number of input elements and returns the result asInteger.static <K> IntCollector<?,Map<K,int[]>>groupingBy(IntFunction<? extends K> classifier)Returns anIntCollectorimplementing a "group by" operation on input numbers, grouping them according to a classification function, and returning the results in aMap.static <K,D,A,M extends Map<K,D>>
IntCollector<?,M>groupingBy(IntFunction<? extends K> classifier, Supplier<M> mapFactory, IntCollector<A,D> downstream)Returns anIntCollectorimplementing 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 downstreamIntCollector.static <K,D,A>
IntCollector<?,Map<K,D>>groupingBy(IntFunction<? extends K> classifier, IntCollector<A,D> downstream)Returns anIntCollectorimplementing 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 downstreamIntCollector.ObjIntConsumer<A>intAccumulator()A function that folds a value into a mutable result container.static IntCollector<?,String>joining(CharSequence delimiter)Returns anIntCollectorthat converts the input numbers to strings and concatenates them, separated by the specified delimiter, in encounter order.static IntCollector<?,String>joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)Returns anIntCollectorthat converts the input numbers to strings and concatenates them, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.static <A,R>
IntCollector<?,R>mapping(IntUnaryOperator mapper, IntCollector<A,R> downstream)Adapts anIntCollectorto another one by applying a mapping function to each input element before accumulation.static <U,A,R>
IntCollector<?,R>mappingToObj(IntFunction<U> mapper, Collector<U,A,R> downstream)Adapts aCollectoraccepting elements of typeUto anIntCollectorby applying a mapping function to each input element before accumulation.static IntCollector<?,OptionalInt>max()Returns anIntCollectorthat produces the maximal element, described as anOptionalInt.BiConsumer<A,A>merger()A function that merges the second partial result into the first partial result.static IntCollector<?,OptionalInt>min()Returns anIntCollectorthat produces the minimal element, described as anOptionalInt.static <A,R>
IntCollector<A,R>of(Supplier<A> supplier, ObjIntConsumer<A> intAccumulator, BiConsumer<A,A> merger, Function<A,R> finisher)Returns a newIntCollectordescribed by the givensupplier,accumulator,merger, andfinisherfunctions.static <R> IntCollector<R,R>of(Supplier<R> supplier, ObjIntConsumer<R> intAccumulator, BiConsumer<R,R> merger)Returns a newIntCollectordescribed by the givensupplier,accumulator, andmergerfunctions.static <A,R>
IntCollector<?,R>of(Collector<Integer,A,R> collector)Adapts aCollectorwhich accepts elements of typeIntegerto anIntCollector.static IntCollector<?,Map<Boolean,int[]>>partitioningBy(IntPredicate predicate)Returns anIntCollectorwhich partitions the input elements according to anIntPredicate, and organizes them into aMap<Boolean, int[]>.static <A,D>
IntCollector<?,Map<Boolean,D>>partitioningBy(IntPredicate predicate, IntCollector<A,D> downstream)Returns anIntCollectorwhich partitions the input numbers according to anIntPredicate, reduces the values in each partition according to anotherIntCollector, and organizes them into aMap<Boolean, D>whose values are the result of the downstream reduction.static IntCollector<?,Integer>reducing(int identity, IntBinaryOperator op)Returns anIntCollectorwhich performs a reduction of its input numbers under a specifiedIntBinaryOperatorusing the provided identity.static IntCollector<?,OptionalInt>reducing(IntBinaryOperator op)Returns anIntCollectorwhich performs a reduction of its input numbers under a specifiedIntBinaryOperator.static IntCollector<?,IntSummaryStatistics>summarizing()Returns anIntCollectorwhich returns summary statistics for the input elements.static IntCollector<?,Integer>summing()Returns anIntCollectorthat produces the sum of the input elements.static IntCollector<?,int[]>toArray()Returns anIntCollectorthat produces the array of the input elements.static IntCollector<?,BitSet>toBitSet()Returns anIntCollectorthat produces theBitSetof the input elements.static IntCollector<?,boolean[]>toBooleanArray(IntPredicate predicate)Returns anIntCollectorwhich produces a boolean array containing the results of applying the given predicate to the input elements, in encounter order.static IntCollector<?,byte[]>toByteArray()Returns anIntCollectorthat produces thebyte[]array of the input elements converting them via(byte)casting.static IntCollector<?,char[]>toCharArray()Returns anIntCollectorthat produces thechar[]array of the input elements converting them via(char)casting.static IntCollector<?,short[]>toShortArray()Returns anIntCollectorthat produces theshort[]array of the input elements converting them via(short)casting.-
Methods inherited from interface Collector
characteristics, finisher, supplier
-
-
-
-
Method Detail
-
intAccumulator
ObjIntConsumer<A> intAccumulator()
A function that folds a value into a mutable result container.- Returns:
- a function which folds a value into a mutable result container
-
accumulator
default BiConsumer<A,Integer> accumulator()
A function that folds a value into a mutable result container. The default implementation callsintAccumulator()on unboxed value.- Specified by:
accumulatorin interfaceCollector<Integer,A,R>- Returns:
- a function which folds a value into a mutable result container
-
andThen
default <RR> IntCollector<A,RR> andThen(Function<R,RR> finisher)
Adapts this collector to perform an additional finishing transformation.- Type Parameters:
RR- result type of the resulting collector- Parameters:
finisher- a function to be applied to the final result of this collector- Returns:
- a collector which performs the action of this collector, followed by an additional finishing step
- Since:
- 0.3.7
-
of
static <R> IntCollector<R,R> of(Supplier<R> supplier, ObjIntConsumer<R> intAccumulator, BiConsumer<R,R> merger)
Returns a newIntCollectordescribed by the givensupplier,accumulator, andmergerfunctions. The resultingIntCollectorhas theCollector.Characteristics.IDENTITY_FINISHcharacteristic.- Type Parameters:
R- The type of intermediate accumulation result, and final result, for the new collector- Parameters:
supplier- The supplier function for the new collectorintAccumulator- The intAccumulator function for the new collectormerger- The merger function for the new collector- Returns:
- the new
IntCollector
-
of
static <A,R> IntCollector<?,R> of(Collector<Integer,A,R> collector)
Adapts aCollectorwhich accepts elements of typeIntegerto anIntCollector.- Type Parameters:
A- The intermediate accumulation type of the collectorR- The final result type of the collector- Parameters:
collector- aCollectorto adapt- Returns:
- an
IntCollectorwhich behaves in the same way as input collector.
-
of
static <A,R> IntCollector<A,R> of(Supplier<A> supplier, ObjIntConsumer<A> intAccumulator, BiConsumer<A,A> merger, Function<A,R> finisher)
Returns a newIntCollectordescribed by the givensupplier,accumulator,merger, andfinisherfunctions.- Type Parameters:
A- The intermediate accumulation type of the new collectorR- The final result type of the new collector- Parameters:
supplier- The supplier function for the new collectorintAccumulator- The intAccumulator function for the new collectormerger- The merger function for the new collectorfinisher- The finisher function for the new collector- Returns:
- the new
IntCollector
-
joining
static IntCollector<?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Returns anIntCollectorthat converts the input numbers to strings and concatenates them, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.- Parameters:
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 result- Returns:
- An
IntCollectorwhich concatenates the input numbers, separated by the specified delimiter, in encounter order
-
joining
static IntCollector<?,String> joining(CharSequence delimiter)
Returns anIntCollectorthat converts the input numbers to strings and concatenates them, separated by the specified delimiter, in encounter order.- Parameters:
delimiter- the delimiter to be used between each element- Returns:
- An
IntCollectorwhich concatenates the input numbers, separated by the specified delimiter, in encounter order
-
counting
static IntCollector<?,Long> counting()
Returns anIntCollectorthat counts the number of input elements and returns the result asLong. If no elements are present, the result is 0.- Returns:
- an
IntCollectorthat counts the input elements
-
countingInt
static IntCollector<?,Integer> countingInt()
Returns anIntCollectorthat counts the number of input elements and returns the result asInteger. If no elements are present, the result is 0.- Returns:
- an
IntCollectorthat counts the input elements
-
summing
static IntCollector<?,Integer> summing()
Returns anIntCollectorthat produces the sum of the input elements. If no elements are present, the result is 0.- Returns:
- an
IntCollectorthat produces the sum of the input elements
-
averaging
static IntCollector<?,OptionalDouble> averaging()
Returns anIntCollectorthat produces the arithmetic mean of the input elements or an empty optional if no elements are collected.Note that unlike
IntStream.average(),Collectors.averagingInt(java.util.function.ToIntFunction)andIntSummaryStatistics.getAverage()this collector does not overflow if an intermediate sum exceedsLong.MAX_VALUE.- Returns:
- an
IntCollectorthat produces the arithmetic mean of the input elements - Since:
- 0.3.7
-
min
static IntCollector<?,OptionalInt> min()
Returns anIntCollectorthat produces the minimal element, described as anOptionalInt. If no elements are present, the result is an emptyOptionalInt.- Returns:
- an
IntCollectorthat produces the minimal element.
-
max
static IntCollector<?,OptionalInt> max()
Returns anIntCollectorthat produces the maximal element, described as anOptionalInt. If no elements are present, the result is an emptyOptionalInt.- Returns:
- an
IntCollectorthat produces the maximal element.
-
mapping
static <A,R> IntCollector<?,R> mapping(IntUnaryOperator mapper, IntCollector<A,R> downstream)
Adapts anIntCollectorto another one by applying a mapping function to each input element before accumulation.- Type Parameters:
A- intermediate accumulation type of the downstream collectorR- result type of collector- Parameters:
mapper- a function to be applied to the input elementsdownstream- a collector which will accept mapped values- Returns:
- a collector which applies the mapping function to the input elements and provides the mapped results to the downstream collector
-
mappingToObj
static <U,A,R> IntCollector<?,R> mappingToObj(IntFunction<U> mapper, Collector<U,A,R> downstream)
Adapts aCollectoraccepting elements of typeUto anIntCollectorby applying a mapping function to each input element before accumulation.- Type Parameters:
U- type of elements accepted by downstream collectorA- intermediate accumulation type of the downstream collectorR- result type of collector- Parameters:
mapper- a function to be applied to the input elementsdownstream- a collector which will accept mapped values- Returns:
- a collector which applies the mapping function to the input elements and provides the mapped results to the downstream collector
-
reducing
static IntCollector<?,OptionalInt> reducing(IntBinaryOperator op)
Returns anIntCollectorwhich performs a reduction of its input numbers under a specifiedIntBinaryOperator. The result is described as anOptionalInt.- Parameters:
op- anIntBinaryOperatorused to reduce the input numbers- Returns:
- an
IntCollectorwhich implements the reduction operation.
-
reducing
static IntCollector<?,Integer> reducing(int identity, IntBinaryOperator op)
Returns anIntCollectorwhich performs a reduction of its input numbers under a specifiedIntBinaryOperatorusing the provided identity.- Parameters:
identity- the identity value for the reduction (also, the value that is returned when there are no input elements)op- anIntBinaryOperatorused to reduce the input numbers- Returns:
- an
IntCollectorwhich implements the reduction operation
-
summarizing
static IntCollector<?,IntSummaryStatistics> summarizing()
Returns anIntCollectorwhich returns summary statistics for the input elements.- Returns:
- an
IntCollectorimplementing the summary-statistics reduction
-
partitioningBy
static IntCollector<?,Map<Boolean,int[]>> partitioningBy(IntPredicate predicate)
Returns anIntCollectorwhich partitions the input elements according to anIntPredicate, and organizes them into aMap<Boolean, int[]>. There are no guarantees on the type, mutability, serializability, or thread-safety of theMapreturned.- Parameters:
predicate- a predicate used for classifying input elements- Returns:
- an
IntCollectorimplementing the partitioning operation
-
partitioningBy
static <A,D> IntCollector<?,Map<Boolean,D>> partitioningBy(IntPredicate predicate, IntCollector<A,D> downstream)
Returns anIntCollectorwhich partitions the input numbers according to anIntPredicate, reduces the values in each partition according to anotherIntCollector, and organizes them into aMap<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
Mapreturned.- Type Parameters:
A- the intermediate accumulation type of the downstream collectorD- the result type of the downstream reduction- Parameters:
predicate- a predicate used for classifying input elementsdownstream- anIntCollectorimplementing the downstream reduction- Returns:
- an
IntCollectorimplementing the cascaded partitioning operation
-
groupingBy
static <K> IntCollector<?,Map<K,int[]>> groupingBy(IntFunction<? extends K> classifier)
Returns anIntCollectorimplementing a "group by" operation on input numbers, grouping them according to a classification function, and returning the results in aMap.The classification function maps elements to some key type
K. The collector produces aMap<K, int[]>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
Mapobjects returned.- Type Parameters:
K- the type of the keys- Parameters:
classifier- the classifier function mapping input elements to keys- Returns:
- an
IntCollectorimplementing the group-by operation
-
groupingBy
static <K,D,A> IntCollector<?,Map<K,D>> groupingBy(IntFunction<? extends K> classifier, IntCollector<A,D> downstream)
Returns anIntCollectorimplementing 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 downstreamIntCollector.The classification function maps elements to some key type
K. The downstream collector produces a result of typeD. The resulting collector produces aMap<K, D>.There are no guarantees on the type, mutability, serializability, or thread-safety of the
Mapreturned.- Type Parameters:
K- the type of the keysA- the intermediate accumulation type of the downstream collectorD- the result type of the downstream reduction- Parameters:
classifier- a classifier function mapping input elements to keysdownstream- anIntCollectorimplementing the downstream reduction- Returns:
- an
IntCollectorimplementing the cascaded group-by operation
-
groupingBy
static <K,D,A,M extends Map<K,D>> IntCollector<?,M> groupingBy(IntFunction<? extends K> classifier, Supplier<M> mapFactory, IntCollector<A,D> downstream)
Returns anIntCollectorimplementing 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 downstreamIntCollector. TheMapproduced 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 typeD. The resulting collector produces aMap<K, D>.- Type Parameters:
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 resultingMap- Parameters:
classifier- a classifier function mapping input elements to keysdownstream- anIntCollectorimplementing the downstream reductionmapFactory- a function which, when called, produces a new emptyMapof the desired type- Returns:
- an
IntCollectorimplementing the cascaded group-by operation
-
toBitSet
static IntCollector<?,BitSet> toBitSet()
Returns anIntCollectorthat produces theBitSetof the input elements.- Returns:
- an
IntCollectorthat produces theBitSetof the input elements
-
toArray
static IntCollector<?,int[]> toArray()
Returns anIntCollectorthat produces the array of the input elements. If no elements are present, the result is an empty array.- Returns:
- an
IntCollectorthat produces the array of the input elements
-
toByteArray
static IntCollector<?,byte[]> toByteArray()
Returns anIntCollectorthat produces thebyte[]array of the input elements converting them via(byte)casting. If no elements are present, the result is an empty array.- Returns:
- an
IntCollectorthat produces thebyte[]array of the input elements
-
toCharArray
static IntCollector<?,char[]> toCharArray()
Returns anIntCollectorthat produces thechar[]array of the input elements converting them via(char)casting. If no elements are present, the result is an empty array.- Returns:
- an
IntCollectorthat produces thechar[]array of the input elements
-
toShortArray
static IntCollector<?,short[]> toShortArray()
Returns anIntCollectorthat produces theshort[]array of the input elements converting them via(short)casting. If no elements are present, the result is an empty array.- Returns:
- an
IntCollectorthat produces theshort[]array of the input elements
-
toBooleanArray
static IntCollector<?,boolean[]> toBooleanArray(IntPredicate predicate)
Returns anIntCollectorwhich produces a boolean array containing the results of applying the given predicate to the input elements, in encounter order.- Parameters:
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.- Returns:
- an
IntCollectorwhich collects the results of the predicate function to the boolean array, in encounter order. - Since:
- 0.3.8
-
merger
BiConsumer<A,A> merger()
A function that merges the second partial result into the first partial result.- Returns:
- a function that merges the second partial result into the first partial result.
-
combiner
default BinaryOperator<A> combiner()
A function that accepts two partial results and combines them returning either existing partial result or new one. The default implementation calls themerger()and returns the first partial result.
-
-