Class Collectors

java.lang.Object
com.terracottatech.store.function.Collectors

public final class Collectors extends Object
Provides functionally transparent equivalent collectors to Collectors.

The methods in this class provide Collector implementations that can be optimized by TCStore. The equivalent java.util.stream.Collectors methods are functionally-opaque and cannot be optimized by TCStore.

  • Constructor Details

    • Collectors

      public Collectors()
  • Method Details

    • composite

      @SafeVarargs public static <T> Collector<T,List<Object>,List<Object>> composite(Collector<T,?,?>... collectors)
      Runs a list of Collectors accepting elements of type U in parallel against the same sequence of elements.
      Type Parameters:
      T - the type of the input elements
      Parameters:
      collectors - a list of downstream collectors which will accept the elements
      Returns:
      a collector which provides the elements to all the downstream collectors
    • filtering

      public static <T, A, R> Collector<T,A,R> filtering(Predicate<? super T> predicate, Collector<T,A,R> downstream)
      Functionally transparent version of java.util.stream.Collectors.filtering(Predicate, Collector) (a method added in Java 9).
      Type Parameters:
      T - the type of the input elements
      A - intermediate accumulation type of the downstream collector
      R - result type of collector
      Parameters:
      predicate - a predicate to be applied to the input elements
      downstream - a collector which will accept values that match the predicate
      Returns:
      a collector which applies the predicate to the input elements and provides matching elements to the downstream collector
    • mapping

      public static <T, U, A, R> Collector<T,?,R> mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream)
      Functionally transparent version of Collectors.mapping(Function, Collector)
      Type Parameters:
      T - the type of the input elements
      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
    • counting

      public static <T> Collector<T,?,Long> counting()
      Functionally transparent version of Collectors.counting()
      Type Parameters:
      T - the type of the input elements
      Returns:
      a Collector that counts the input elements
    • minBy

      public static <T> Collector<T,?,Optional<T>> minBy(Comparator<? super T> comparator)
      Functionally transparent version of Collectors.minBy(Comparator)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      comparator - a Comparator for comparing elements
      Returns:
      a Collector that produces the minimal value
    • maxBy

      public static <T> Collector<T,?,Optional<T>> maxBy(Comparator<? super T> comparator)
      Functionally transparent version of Collectors.maxBy(Comparator)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      comparator - a Comparator for comparing elements
      Returns:
      a Collector that produces the maximal value
    • summingInt

      public static <T> Collector<T,?,Integer> summingInt(ToIntFunction<? super T> mapper)
      Functionally transparent version of Collectors.summingInt(ToIntFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the sum of a derived property
    • summingLong

      public static <T> Collector<T,?,Long> summingLong(ToLongFunction<? super T> mapper)
      Functionally transparent version of Collectors.summingLong(ToLongFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the sum of a derived property
    • summingDouble

      public static <T> Collector<T,?,Double> summingDouble(ToDoubleFunction<? super T> mapper)
      Functionally transparent version of Collectors.summingDouble(ToDoubleFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the sum of a derived property
    • averagingInt

      public static <T> Collector<T,?,Double> averagingInt(ToIntFunction<? super T> mapper)
      Functionally transparent version of Collectors.averagingInt(ToIntFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the mean of a derived property
    • averagingLong

      public static <T> Collector<T,?,Double> averagingLong(ToLongFunction<? super T> mapper)
      Functionally transparent version of Collectors.averagingLong(ToLongFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the mean of a derived property
    • averagingDouble

      public static <T> Collector<T,?,Double> averagingDouble(ToDoubleFunction<? super T> mapper)
      Functionally transparent version of Collectors.averagingDouble(ToDoubleFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      Returns:
      a Collector that produces the mean of a derived property
    • groupingBy

      public static <T, K, A, D> Collector<T,?,Map<K,D>> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
      Functionally transparent version of Collectors.groupingBy(Function, Collector)
      Type Parameters:
      T - the type of the input elements
      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 Collector implementing the downstream reduction
      Returns:
      a Collector implementing the cascaded group-by operation
    • groupingByConcurrent

      public static <T, K, A, D> Collector<T,?,ConcurrentMap<K,D>> groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
      Functionally transparent version of Collectors.groupingByConcurrent(Function, Collector)
      Type Parameters:
      T - the type of the input elements
      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 Collector implementing the downstream reduction
      Returns:
      a concurrent, unordered Collector implementing the cascaded group-by operation
    • partitioningBy

      public static <T, D, A> Collector<T,?,Map<Boolean,D>> partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)
      Functionally transparent version of Collectors.partitioningBy(Predicate, Collector)
      Type Parameters:
      T - the type of the input elements
      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 Collector implementing the downstream reduction
      Returns:
      a Collector implementing the cascaded partitioning operation
    • summarizingInt

      public static <T> Collector<T,?,IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper)
      Functionally transparent version of Collectors.summarizingInt(ToIntFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a mapping function to apply to each element
      Returns:
      a Collector implementing the summary-statistics reduction
    • summarizingLong

      public static <T> Collector<T,?,LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper)
      Functionally transparent version of Collectors.summarizingLong(ToLongFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a mapping function to apply to each element
      Returns:
      a Collector implementing the summary-statistics reduction
    • summarizingDouble

      public static <T> Collector<T,?,DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper)
      Functionally transparent version of Collectors.summarizingDouble(ToDoubleFunction)
      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a mapping function to apply to each element
      Returns:
      a Collector implementing the summary-statistics reduction
    • toSet

      public static <T> Collector<T,?,Set<T>> toSet()
      Functionally transparent version of Collectors.toSet()
      Type Parameters:
      T - the type of the input elements
      Returns:
      a Collector which collects all the input elements into a Set
    • collectingAndThen

      public static <T, A, R, RR> Collector<T,A,RR> collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)
      Functionally transparent version of Collectors.collectingAndThen(Collector, Function)
      Type Parameters:
      T - the type of the input elements
      Returns:
      a Collector which collects all the input elements into a Set
    • varianceOf

      @Deprecated public static <T> Collector<T,?,Optional<Double>> varianceOf(ToIntFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of an integer-valued function applied to the input elements.

      This method is deprecated in favor of varianceOfInt(ToIntFunction, VarianceType) as this method is overloaded in an ambiguous manner by the other type variant variance collector methods.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property
    • varianceOfInt

      public static <T> Collector<T,?,Optional<Double>> varianceOfInt(ToIntFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of an integer-valued function applied to the input elements.

      Population or sample variance can be selected using the type argument. If the variance type is Collectors.VarianceType.POPULATION and no elements are present, the result is an empty optional. If the variance type is Collectors.VarianceType.SAMPLE and less than two elements are present, then result is an empty optional.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property
    • varianceOf

      @Deprecated public static <T> Collector<T,?,Optional<Double>> varianceOf(ToLongFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of a long-valued function applied to the input elements.

      This method is deprecated in favor of varianceOfLong(ToLongFunction, VarianceType) as this method is overloaded in an ambiguous manner by the other type variant variance collector methods.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property
    • varianceOfLong

      public static <T> Collector<T,?,Optional<Double>> varianceOfLong(ToLongFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of a long-valued function applied to the input elements.

      Population or sample variance can be selected using the type argument. If the variance type is Collectors.VarianceType.POPULATION and no elements are present, the result is an empty optional. If the variance type is Collectors.VarianceType.SAMPLE and less than two elements are present, then result is an empty optional.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property
    • varianceOf

      @Deprecated public static <T> Collector<T,?,Optional<Double>> varianceOf(ToDoubleFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of a double-valued function applied to the input elements.

      This method is deprecated in favor of varianceOfDouble(ToDoubleFunction, VarianceType) as this method is overloaded in an ambiguous manner by the other type variant variance collector methods.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property
    • varianceOfDouble

      public static <T> Collector<T,?,Optional<Double>> varianceOfDouble(ToDoubleFunction<T> mapper, Collectors.VarianceType type)
      Returns a Collector that produces the statistical variance of a double-valued function applied to the input elements.

      Population or sample variance can be selected using the type argument. If the variance type is Collectors.VarianceType.POPULATION and no elements are present, the result is an empty optional. If the variance type is Collectors.VarianceType.SAMPLE and less than two elements are present, then result is an empty optional.

      Type Parameters:
      T - the type of the input elements
      Parameters:
      mapper - a function extracting the property to be summed
      type - the requested variance type
      Returns:
      a Collector that produces the variance of a derived property