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:
    java.util.stream.Collector<java.lang.Integer,​A,​R>, MergingCollector<java.lang.Integer,​A,​R>
    All Known Implementing Classes:
    Internals.IntCollectorImpl

    public interface IntCollector<A,​R>
    extends MergingCollector<java.lang.Integer,​A,​R>
    A Collector specialized to work with primitive int.
    Since:
    0.3.0
    See Also:
    IntStreamEx.collect(IntCollector)
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.stream.Collector

        java.util.stream.Collector.Characteristics
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.util.function.BiConsumer<A,​java.lang.Integer> accumulator()
      A function that folds a value into a mutable result container.
      default <RR> IntCollector<A,​RR> andThen​(java.util.function.Function<R,​RR> finisher)
      Adapts this collector to perform an additional finishing transformation.
      static IntCollector<?,​java.util.OptionalDouble> averaging()
      Returns an IntCollector that produces the arithmetic mean of the input elements or an empty optional if no elements are collected.
      static IntCollector<?,​java.lang.Long> counting()
      Returns an IntCollector that counts the number of input elements and returns the result as Long.
      static IntCollector<?,​java.lang.Integer> countingInt()
      Returns an IntCollector that counts the number of input elements and returns the result as Integer.
      static <K> IntCollector<?,​java.util.Map<K,​int[]>> groupingBy​(java.util.function.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.
      static <K,​D,​A,​M extends java.util.Map<K,​D>>
      IntCollector<?,​M>
      groupingBy​(java.util.function.IntFunction<? extends K> classifier, java.util.function.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.
      static <K,​D,​A>
      IntCollector<?,​java.util.Map<K,​D>>
      groupingBy​(java.util.function.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.
      java.util.function.ObjIntConsumer<A> intAccumulator()
      A function that folds a value into a mutable result container.
      static IntCollector<?,​java.lang.String> joining​(java.lang.CharSequence delimiter)
      Returns an IntCollector that converts the input numbers to strings and concatenates them, separated by the specified delimiter, in encounter order.
      static IntCollector<?,​java.lang.String> joining​(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.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.
      static <A,​R>
      IntCollector<?,​R>
      mapping​(java.util.function.IntUnaryOperator mapper, IntCollector<A,​R> downstream)
      Adapts an IntCollector to another one by applying a mapping function to each input element before accumulation.
      static <U,​A,​R>
      IntCollector<?,​R>
      mappingToObj​(java.util.function.IntFunction<U> mapper, java.util.stream.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.
      static IntCollector<?,​java.util.OptionalInt> max()
      Returns an IntCollector that produces the maximal element, described as an OptionalInt.
      static IntCollector<?,​java.util.OptionalInt> min()
      Returns an IntCollector that produces the minimal element, described as an OptionalInt.
      static <A,​R>
      IntCollector<A,​R>
      of​(java.util.function.Supplier<A> supplier, java.util.function.ObjIntConsumer<A> intAccumulator, java.util.function.BiConsumer<A,​A> merger, java.util.function.Function<A,​R> finisher)
      Returns a new IntCollector described by the given supplier, accumulator, merger, and finisher functions.
      static <R> IntCollector<R,​R> of​(java.util.function.Supplier<R> supplier, java.util.function.ObjIntConsumer<R> intAccumulator, java.util.function.BiConsumer<R,​R> merger)
      Returns a new IntCollector described by the given supplier, accumulator, and merger functions.
      static <A,​R>
      IntCollector<?,​R>
      of​(java.util.stream.Collector<java.lang.Integer,​A,​R> collector)
      Adapts a Collector which accepts elements of type Integer to an IntCollector.
      static IntCollector<?,​java.util.Map<java.lang.Boolean,​int[]>> partitioningBy​(java.util.function.IntPredicate predicate)
      Returns an IntCollector which partitions the input elements according to an IntPredicate, and organizes them into a Map<Boolean, int[]>.
      static <A,​D>
      IntCollector<?,​java.util.Map<java.lang.Boolean,​D>>
      partitioningBy​(java.util.function.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.
      static IntCollector<?,​java.lang.Integer> reducing​(int identity, java.util.function.IntBinaryOperator op)
      Returns an IntCollector which performs a reduction of its input numbers under a specified IntBinaryOperator using the provided identity.
      static IntCollector<?,​java.util.OptionalInt> reducing​(java.util.function.IntBinaryOperator op)
      Returns an IntCollector which performs a reduction of its input numbers under a specified IntBinaryOperator.
      static IntCollector<?,​java.util.IntSummaryStatistics> summarizing()
      Returns an IntCollector which returns summary statistics for the input elements.
      static IntCollector<?,​java.lang.Integer> summing()
      Returns an IntCollector that produces the sum of the input elements.
      static IntCollector<?,​int[]> toArray()
      Returns an IntCollector that produces the array of the input elements.
      static IntCollector<?,​java.util.BitSet> toBitSet()
      Returns an IntCollector that produces the BitSet of the input elements.
      static IntCollector<?,​boolean[]> toBooleanArray​(java.util.function.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.
      static IntCollector<?,​byte[]> toByteArray()
      Returns an IntCollector that produces the byte[] array of the input elements converting them via (byte) casting.
      static IntCollector<?,​char[]> toCharArray()
      Returns an IntCollector that produces the char[] array of the input elements converting them via (char) casting.
      static IntCollector<?,​short[]> toShortArray()
      Returns an IntCollector that produces the short[] array of the input elements converting them via (short) casting.
      • Methods inherited from interface java.util.stream.Collector

        characteristics, finisher, supplier
    • Method Detail

      • intAccumulator

        java.util.function.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 java.util.function.BiConsumer<A,​java.lang.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 java.util.stream.Collector<java.lang.Integer,​A,​R>
        Returns:
        a function which folds a value into a mutable result container
      • andThen

        default <RR> IntCollector<A,​RR> andThen​(java.util.function.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​(java.util.function.Supplier<R> supplier,
                                              java.util.function.ObjIntConsumer<R> intAccumulator,
                                              java.util.function.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​(java.util.stream.Collector<java.lang.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​(java.util.function.Supplier<A> supplier,
                                                      java.util.function.ObjIntConsumer<A> intAccumulator,
                                                      java.util.function.BiConsumer<A,​A> merger,
                                                      java.util.function.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<?,​java.lang.String> joining​(java.lang.CharSequence delimiter,
                                                              java.lang.CharSequence prefix,
                                                              java.lang.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<?,​java.lang.String> joining​(java.lang.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<?,​java.lang.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<?,​java.lang.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<?,​java.lang.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
      • averaging

        static IntCollector<?,​java.util.OptionalDouble> averaging()
        Returns an IntCollector that 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) and IntSummaryStatistics.getAverage() this collector does not overflow if an intermediate sum exceeds Long.MAX_VALUE.

        Returns:
        an IntCollector that produces the arithmetic mean of the input elements
        Since:
        0.3.7
      • min

        static IntCollector<?,​java.util.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<?,​java.util.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​(java.util.function.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​(java.util.function.IntFunction<U> mapper,
                                                                        java.util.stream.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<?,​java.util.OptionalInt> reducing​(java.util.function.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<?,​java.lang.Integer> reducing​(int identity,
                                                                java.util.function.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<?,​java.util.IntSummaryStatistics> summarizing()
        Returns an IntCollector which returns summary statistics for the input elements.
        Returns:
        an IntCollector implementing the summary-statistics reduction
      • partitioningBy

        static IntCollector<?,​java.util.Map<java.lang.Boolean,​int[]>> partitioningBy​(java.util.function.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<?,​java.util.Map<java.lang.Boolean,​D>> partitioningBy​(java.util.function.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<?,​java.util.Map<K,​int[]>> groupingBy​(java.util.function.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<?,​java.util.Map<K,​D>> groupingBy​(java.util.function.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 java.util.Map<K,​D>> IntCollector<?,​M> groupingBy​(java.util.function.IntFunction<? extends K> classifier,
                                                                                                               java.util.function.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<?,​java.util.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​(java.util.function.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