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
    All Superinterfaces:
    Collector<Integer,​A,​R>

    public interface IntCollector<A,​R>
    A Collector specialized to work with primitive int.
    Since:
    0.3.0
    Author:
    Tagir Valeev
    See Also:
    IntStreamEx.collect(IntCollector)
    • 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 calls intAccumulator() on unboxed value.
        Specified by:
        accumulator in interface Collector<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 new IntCollector described by the given supplier, accumulator, and merger functions. The resulting IntCollector has the Collector.Characteristics.IDENTITY_FINISH characteristic.
        Type Parameters:
        R - The type of intermediate accumulation result, and final result, for the new collector
        Parameters:
        supplier - The supplier function for the new collector
        intAccumulator - The intAccumulator function for the new collector
        merger - The merger function for the new collector
        Returns:
        the new IntCollector
      • of

        static <A,​R> IntCollector<?,​R> of​(Collector<Integer,​A,​R> collector)
        Adapts a Collector which accepts elements of type Integer to an IntCollector.
        Type Parameters:
        A - The intermediate accumulation type of the collector
        R - The final result type of the collector
        Parameters:
        collector - a Collector to adapt
        Returns:
        an IntCollector which 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 new IntCollector described by the given supplier, accumulator, merger, and finisher functions.
        Type Parameters:
        A - The intermediate accumulation type of the new collector
        R - The final result type of the new collector
        Parameters:
        supplier - The supplier function for the new collector
        intAccumulator - The intAccumulator function for the new collector
        merger - The merger function for the new collector
        finisher - The finisher function for the new collector
        Returns:
        the new IntCollector
      • joining

        static IntCollector<?,​String> joining​(CharSequence delimiter,
                                                    CharSequence prefix,
                                                    CharSequence suffix)
        Returns an IntCollector that 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 element
        prefix - the sequence of characters to be used at the beginning of the joined result
        suffix - the sequence of characters to be used at the end of the joined result
        Returns:
        An IntCollector which concatenates the input numbers, separated by the specified delimiter, in encounter order
      • joining

        static IntCollector<?,​String> joining​(CharSequence delimiter)
        Returns an IntCollector that 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 IntCollector which concatenates the input numbers, separated by the specified delimiter, in encounter order
      • counting

        static IntCollector<?,​Long> counting()
        Returns an IntCollector that counts the number of input elements and returns the result as Long. If no elements are present, the result is 0.
        Returns:
        an IntCollector that counts the input elements
      • countingInt

        static IntCollector<?,​Integer> countingInt()
        Returns an IntCollector that counts the number of input elements and returns the result as Integer. If no elements are present, the result is 0.
        Returns:
        an IntCollector that counts the input elements
      • summing

        static IntCollector<?,​Integer> summing()
        Returns an IntCollector that produces the sum of the input elements. If no elements are present, the result is 0.
        Returns:
        an IntCollector that produces the sum of the input elements
      • min

        static IntCollector<?,​OptionalInt> min()
        Returns an IntCollector that produces the minimal element, described as an OptionalInt. If no elements are present, the result is an empty OptionalInt.
        Returns:
        an IntCollector that produces the minimal element.
      • max

        static IntCollector<?,​OptionalInt> max()
        Returns an IntCollector that produces the maximal element, described as an OptionalInt. If no elements are present, the result is an empty OptionalInt.
        Returns:
        an IntCollector that produces the maximal element.
      • mapping

        static <A,​R> IntCollector<?,​R> mapping​(IntUnaryOperator mapper,
                                                           IntCollector<A,​R> downstream)
        Adapts an IntCollector to another one by applying a mapping function to each input element before accumulation.
        Type Parameters:
        A - intermediate accumulation type of the downstream collector
        R - result type of collector
        Parameters:
        mapper - a function to be applied to the input elements
        downstream - 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 a Collector accepting elements of type U to an IntCollector by applying a mapping function to each input element before accumulation.
        Type Parameters:
        U - type of elements accepted by downstream collector
        A - intermediate accumulation type of the downstream collector
        R - result type of collector
        Parameters:
        mapper - a function to be applied to the input elements
        downstream - 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 an IntCollector which performs a reduction of its input numbers under a specified IntBinaryOperator. The result is described as an OptionalInt.
        Parameters:
        op - an IntBinaryOperator used to reduce the input numbers
        Returns:
        an IntCollector which implements the reduction operation.
      • reducing

        static IntCollector<?,​Integer> reducing​(int identity,
                                                      IntBinaryOperator op)
        Returns an IntCollector which performs a reduction of its input numbers under a specified IntBinaryOperator using the provided identity.
        Parameters:
        identity - the identity value for the reduction (also, the value that is returned when there are no input elements)
        op - an IntBinaryOperator used to reduce the input numbers
        Returns:
        an IntCollector which implements the reduction operation
      • summarizing

        static IntCollector<?,​IntSummaryStatistics> summarizing()
        Returns an IntCollector which returns summary statistics for the input elements.
        Returns:
        an IntCollector implementing the summary-statistics reduction
      • partitioningBy

        static IntCollector<?,​Map<Boolean,​int[]>> partitioningBy​(IntPredicate predicate)
        Returns an IntCollector which partitions the input elements according to an IntPredicate, and organizes them into a Map<Boolean, int[]>. There are no guarantees on the type, mutability, serializability, or thread-safety of the Map returned.
        Parameters:
        predicate - a predicate used for classifying input elements
        Returns:
        an IntCollector implementing the partitioning operation
      • partitioningBy

        static <A,​D> IntCollector<?,​Map<Boolean,​D>> partitioningBy​(IntPredicate predicate,
                                                                                     IntCollector<A,​D> downstream)
        Returns an IntCollector which partitions the input numbers according to an IntPredicate, 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.

        Type Parameters:
        A - the intermediate accumulation type of the downstream collector
        D - the result type of the downstream reduction
        Parameters:
        predicate - a predicate used for classifying input elements
        downstream - an IntCollector implementing the downstream reduction
        Returns:
        an IntCollector implementing the cascaded partitioning operation
      • groupingBy

        static <K> IntCollector<?,​Map<K,​int[]>> groupingBy​(IntFunction<? extends K> classifier)
        Returns an IntCollector 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, 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 Map objects returned.

        Type Parameters:
        K - the type of the keys
        Parameters:
        classifier - the classifier function mapping input elements to keys
        Returns:
        an IntCollector implementing the group-by operation
      • groupingBy

        static <K,​D,​A> IntCollector<?,​Map<K,​D>> groupingBy​(IntFunction<? extends K> classifier,
                                                                                   IntCollector<A,​D> downstream)
        Returns an IntCollector 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.

        Type Parameters:
        K - the type of the keys
        A - the intermediate accumulation type of the downstream collector
        D - the result type of the downstream reduction
        Parameters:
        classifier - a classifier function mapping input elements to keys
        downstream - an IntCollector implementing the downstream reduction
        Returns:
        an IntCollector implementing 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 an IntCollector 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>.

        Type Parameters:
        K - the type of the keys
        A - the intermediate accumulation type of the downstream collector
        D - the result type of the downstream reduction
        M - the type of the resulting Map
        Parameters:
        classifier - a classifier function mapping input elements to keys
        downstream - an IntCollector implementing the downstream reduction
        mapFactory - a function which, when called, produces a new empty Map of the desired type
        Returns:
        an IntCollector implementing the cascaded group-by operation
      • toBitSet

        static IntCollector<?,​BitSet> toBitSet()
        Returns an IntCollector that produces the BitSet of the input elements.
        Returns:
        an IntCollector that produces the BitSet of the input elements
      • toArray

        static IntCollector<?,​int[]> toArray()
        Returns an IntCollector that produces the array of the input elements. If no elements are present, the result is an empty array.
        Returns:
        an IntCollector that produces the array of the input elements
      • toByteArray

        static IntCollector<?,​byte[]> toByteArray()
        Returns an IntCollector that produces the byte[] array of the input elements converting them via (byte) casting. If no elements are present, the result is an empty array.
        Returns:
        an IntCollector that produces the byte[] array of the input elements
      • toCharArray

        static IntCollector<?,​char[]> toCharArray()
        Returns an IntCollector that produces the char[] array of the input elements converting them via (char) casting. If no elements are present, the result is an empty array.
        Returns:
        an IntCollector that produces the char[] array of the input elements
      • toShortArray

        static IntCollector<?,​short[]> toShortArray()
        Returns an IntCollector that produces the short[] array of the input elements converting them via (short) casting. If no elements are present, the result is an empty array.
        Returns:
        an IntCollector that produces the short[] array of the input elements
      • toBooleanArray

        static IntCollector<?,​boolean[]> toBooleanArray​(IntPredicate predicate)
        Returns an IntCollector which 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 IntCollector which 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 the merger() and returns the first partial result.
        Specified by:
        combiner in interface Collector<T,​A,​R>
        Returns:
        a function which combines two partial results into a combined result