Interface LongCollector<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<Long,A,R>, MergingCollector<Long,A,R>
All Known Implementing Classes:
Internals.LongCollectorImpl

public interface LongCollector<A,R> extends MergingCollector<Long,A,R>
A Collector specialized to work with primitive long.
Since:
0.3.0
See Also:
  • Method Details

    • longAccumulator

      ObjLongConsumer<A> longAccumulator()
      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,Long> accumulator()
      A function that folds a value into a mutable result container.

      The default implementation calls longAccumulator() on unboxed value.

      Specified by:
      accumulator in interface Collector<Long,A,R>
      Returns:
      a function which folds a value into a mutable result container
    • andThen

      default <RR> LongCollector<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> 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. The resulting LongCollector 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
      longAccumulator - The longAccumulator function for the new collector
      merger - The merger function for the new collector
      Returns:
      the new LongCollector
    • of

      static <A, R> LongCollector<?,R> of(Collector<Long,A,R> collector)
      Adapts a Collector which accepts elements of type Long to a LongCollector.
      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:
      a LongCollector which behaves in the same way as input collector.
    • of

      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.
      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
      longAccumulator - The longAccumulator function for the new collector
      merger - The merger function for the new collector
      finisher - The finisher function for the new collector
      Returns:
      the new LongCollector
    • joining

      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.
      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:
      A LongCollector which concatenates the input numbers, separated by the specified delimiter, in encounter order
    • joining

      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.
      Parameters:
      delimiter - the delimiter to be used between each element
      Returns:
      A LongCollector which concatenates the input numbers, separated by the specified delimiter, in encounter order
    • counting

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

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

      static LongCollector<?,Long> summing()
      Returns a LongCollector that produces the sum of the input elements. If no elements are present, the result is 0.
      Returns:
      a LongCollector that produces the sum of the input elements
    • averaging

      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.

      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.

      Returns:
      a LongCollector that produces the arithmetic mean of the input elements
      Since:
      0.3.7
    • min

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

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

      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.
      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> 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.
      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

      Returns a LongCollector which performs a reduction of its input numbers under a specified LongBinaryOperator. The result is described as an OptionalLong.
      Parameters:
      op - a LongBinaryOperator used to reduce the input numbers
      Returns:
      a LongCollector which implements the reduction operation.
    • reducing

      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.
      Parameters:
      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 numbers
      Returns:
      a LongCollector which implements the reduction operation
    • summarizing

      static LongCollector<?,LongSummaryStatistics> summarizing()
      Returns a LongCollector which returns summary statistics for the input elements.
      Returns:
      a LongCollector implementing the summary-statistics reduction
    • partitioningBy

      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[]>.

      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:
      a LongCollector implementing the partitioning operation
    • partitioningBy

      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.

      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 - a LongCollector implementing the downstream reduction
      Returns:
      a LongCollector implementing the cascaded partitioning operation
    • groupingBy

      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.

      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.

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

      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.

      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 - a LongCollector implementing the downstream reduction
      Returns:
      a LongCollector implementing the cascaded group-by operation
    • groupingBy

      static <K, D, A, M extends Map<K, D>> LongCollector<?,M> 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. 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 - a LongCollector implementing the downstream reduction
      mapFactory - a function which, when called, produces a new empty Map of the desired type
      Returns:
      a LongCollector implementing the cascaded group-by operation
    • toArray

      static LongCollector<?,long[]> toArray()
      Returns a LongCollector that produces the array of the input elements. If no elements are present, the result is an empty array.
      Returns:
      a LongCollector that produces the array of the input elements
    • toBooleanArray

      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.
      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:
      a LongCollector which collects the results of the predicate function to the boolean array, in encounter order.
      Since:
      0.3.8