com.hazelcast.aggregation

## Class Aggregators

- java.lang.Object
- - com.hazelcast.aggregation.Aggregators

-     public final class Aggregators
      extends Object

  A utility class to create basic `Aggregator` instances.

  Min/Max/Average aggregators are type specific, so an integerAvg() aggregator expects all elements to be integers. There is no conversion executed while accumulating, so if there is any other type met an exception will be thrown.

  In order to operate on a generic Number type use the fixedPointSum(), floatingPointSum() and numberAvg() aggregators. All of them will convert the given number to either Long or Double during the accumulation phase. It will result in a lot of allocations since each number has to be converted, but it enables the user to operate on the whole family of numbers. It is especially useful if the numbers given to the aggregators may not be of one type only.

  The attributePath given in the factory method allows the aggregator to operate on the value extracted by navigating to the given attributePath on each object that has been returned from a query. The attribute path may be simple, e.g. "name", or nested "address.city".

  If an aggregator does not accept null values pass a predicate to the aggregate call that will filter them out.

  If the input value or the extracted value is a collection it won't be "unfolded" - so for example count aggregation on "person.postalCodes" will return 1 for each input object and not the size of the collection. In order to calculate the size of the collection use the [any] operator, e.g. "person.postalCodes[any]".

  Since:
    3.8

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalAvg()`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalAvg(String attributePath)`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalMax()`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalMax(String attributePath)`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalMin()`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalMin(String attributePath)`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalSum()`
    `static <I> Aggregator<I,BigDecimal>` | `bigDecimalSum(String attributePath)`
    `static <I> Aggregator<I,BigDecimal>` | `bigIntegerAvg()`
    `static <I> Aggregator<I,BigDecimal>` | `bigIntegerAvg(String attributePath)`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerMax()`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerMax(String attributePath)`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerMin()`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerMin(String attributePath)`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerSum()`
    `static <I> Aggregator<I,BigInteger>` | `bigIntegerSum(String attributePath)`
    `static <I,R extends Comparable> Aggregator<I,R>` | `comparableMax()`
    `static <I,R extends Comparable> Aggregator<I,R>` | `comparableMax(String attributePath)`
    `static <I,R extends Comparable> Aggregator<I,R>` | `comparableMin()`
    `static <I,R extends Comparable> Aggregator<I,R>` | `comparableMin(String attributePath)`
    `static <I> Aggregator<I,Long>` | `count()`
    `static <I> Aggregator<I,Long>` | `count(String attributePath)`
    `static <I,R> Aggregator<I,Set<R>>` | `distinct()`
    `static <I,R> Aggregator<I,Set<R>>` | `distinct(String attributePath)`
    `static <I> Aggregator<I,Double>` | `doubleAvg()`
    `static <I> Aggregator<I,Double>` | `doubleAvg(String attributePath)`
    `static <I> Aggregator<I,Double>` | `doubleMax()`
    `static <I> Aggregator<I,Double>` | `doubleMax(String attributePath)`
    `static <I> Aggregator<I,Double>` | `doubleMin()`
    `static <I> Aggregator<I,Double>` | `doubleMin(String attributePath)`
    `static <I> Aggregator<I,Double>` | `doubleSum()`
    `static <I> Aggregator<I,Double>` | `doubleSum(String attributePath)`
    `static <I> Aggregator<I,Long>` | `fixedPointSum()`
    `static <I> Aggregator<I,Long>` | `fixedPointSum(String attributePath)`
    `static <I> Aggregator<I,Double>` | `floatingPointSum()`
    `static <I> Aggregator<I,Double>` | `floatingPointSum(String attributePath)`
    `static <I> Aggregator<I,Double>` | `integerAvg()`
    `static <I> Aggregator<I,Double>` | `integerAvg(String attributePath)`
    `static <I> Aggregator<I,Integer>` | `integerMax()`
    `static <I> Aggregator<I,Integer>` | `integerMax(String attributePath)`
    `static <I> Aggregator<I,Integer>` | `integerMin()`
    `static <I> Aggregator<I,Integer>` | `integerMin(String attributePath)`
    `static <I> Aggregator<I,Long>` | `integerSum()`
    `static <I> Aggregator<I,Long>` | `integerSum(String attributePath)`
    `static <I> Aggregator<I,Double>` | `longAvg()`
    `static <I> Aggregator<I,Double>` | `longAvg(String attributePath)`
    `static <I> Aggregator<I,Long>` | `longMax()`
    `static <I> Aggregator<I,Long>` | `longMax(String attributePath)`
    `static <I> Aggregator<I,Long>` | `longMin()`
    `static <I> Aggregator<I,Long>` | `longMin(String attributePath)`
    `static <I> Aggregator<I,Long>` | `longSum()`
    `static <I> Aggregator<I,Long>` | `longSum(String attributePath)`
    `static <I> Aggregator<I,I>` | `maxBy(String attributePath)`
    `static <I> Aggregator<I,I>` | `minBy(String attributePath)`
    `static <I> Aggregator<I,Double>` | `numberAvg()`
    `static <I> Aggregator<I,Double>` | `numberAvg(String attributePath)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### count

          public static <I> Aggregator<I,Long> count()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that counts the input values. Accepts nulls as input values. Aggregation result type Long.

    - #### count

          public static <I> Aggregator<I,Long> count(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that counts the input values extracted from the given attributePath. Accepts null input values and null extracted values. Aggregation result type Long.

    - #### distinct

          public static <I,R> Aggregator<I,Set<R>> distinct()

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object.
      Returns:
        an aggregator that calculates the distinct set of input values. Accepts null input values. Aggregation result type is a Set of R.

    - #### distinct

          public static <I,R> Aggregator<I,Set<R>> distinct(String attributePath)

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object.
      Returns:
        an aggregator that calculates the distinct set of input values extracted from the given attributePath. Accepts null input values and null extracted values. Aggregation result type is a Set of R.

    - #### bigDecimalAvg

          public static <I> Aggregator<I,BigDecimal> bigDecimalAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigDecimalAvg

          public static <I> Aggregator<I,BigDecimal> bigDecimalAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigIntegerAvg

          public static <I> Aggregator<I,BigDecimal> bigIntegerAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts only BigInteger input values. Aggregation result type is BigDecimal.

    - #### bigIntegerAvg

          public static <I> Aggregator<I,BigDecimal> bigIntegerAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only BigInteger input values. Aggregation result type is BigDecimal.

    - #### doubleAvg

          public static <I> Aggregator<I,Double> doubleAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### doubleAvg

          public static <I> Aggregator<I,Double> doubleAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### integerAvg

          public static <I> Aggregator<I,Double> integerAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Double.

    - #### integerAvg

          public static <I> Aggregator<I,Double> integerAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Double.

    - #### longAvg

          public static <I> Aggregator<I,Double> longAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts only Long input values (primitive and boxed). Aggregation result type is Double.

    - #### longAvg

          public static <I> Aggregator<I,Double> longAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only Long input values (primitive and boxed). Aggregation result type is Double.

    - #### numberAvg

          public static <I> Aggregator<I,Double> numberAvg()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values. Does NOT accept null input values. Accepts generic Number input values. Aggregation result type is Double.

    - #### numberAvg

          public static <I> Aggregator<I,Double> numberAvg(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the average of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts generic Number input values. Aggregation result type is Double.

    - #### bigDecimalMax

          public static <I> Aggregator<I,BigDecimal> bigDecimalMax()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigDecimalMax

          public static <I> Aggregator<I,BigDecimal> bigDecimalMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigIntegerMax

          public static <I> Aggregator<I,BigInteger> bigIntegerMax()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values and null extracted values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### bigIntegerMax

          public static <I> Aggregator<I,BigInteger> bigIntegerMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values nor null extracted values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### doubleMax

          public static <I> Aggregator<I,Double> doubleMax()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values and null extracted values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### doubleMax

          public static <I> Aggregator<I,Double> doubleMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### integerMax

          public static <I> Aggregator<I,Integer> integerMax()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Integer.

    - #### integerMax

          public static <I> Aggregator<I,Integer> integerMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Integer.

    - #### longMax

          public static <I> Aggregator<I,Long> longMax()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### longMax

          public static <I> Aggregator<I,Long> longMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### comparableMax

          public static <I,R extends Comparable> Aggregator<I,R> comparableMax()

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object (subtype of Comparable)
      Returns:
        an aggregator that calculates the max of the input values. Accepts null input values. Accepts generic Comparable input values. Aggregation result type is R.

    - #### comparableMax

          public static <I,R extends Comparable> Aggregator<I,R> comparableMax(String attributePath)

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object (subtype of Comparable)
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts generic Comparable input values. Aggregation result type is R.

    - #### maxBy

          public static <I> Aggregator<I,I> maxBy(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the max of the input values extracted from the given attributePath and returns the input item containing the maximum value. If multiple items contain the maximum value, any of them is returned. Accepts null input values and null extracted values. Accepts generic Comparable input values.

    - #### bigDecimalMin

          public static <I> Aggregator<I,BigDecimal> bigDecimalMin()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values and null extracted values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigDecimalMin

          public static <I> Aggregator<I,BigDecimal> bigDecimalMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigIntegerMin

          public static <I> Aggregator<I,BigInteger> bigIntegerMin()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values and null extracted values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### bigIntegerMin

          public static <I> Aggregator<I,BigInteger> bigIntegerMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### doubleMin

          public static <I> Aggregator<I,Double> doubleMin()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values and null extracted values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### doubleMin

          public static <I> Aggregator<I,Double> doubleMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### integerMin

          public static <I> Aggregator<I,Integer> integerMin()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values and null extracted values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Integer.

    - #### integerMin

          public static <I> Aggregator<I,Integer> integerMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Integer.

    - #### longMin

          public static <I> Aggregator<I,Long> longMin()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values and null extracted values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### longMin

          public static <I> Aggregator<I,Long> longMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### comparableMin

          public static <I,R extends Comparable> Aggregator<I,R> comparableMin()

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object (subtype of Comparable)
      Returns:
        an aggregator that calculates the min of the input values. Accepts null input values. Accepts generic Comparable input values. Aggregation result type is R.

    - #### comparableMin

          public static <I,R extends Comparable> Aggregator<I,R> comparableMin(String attributePath)

      Type Parameters:
        `I` - type of the input object.
        `R` - type of the return object (subtype of Comparable)
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath. Accepts null input values and null extracted values. Accepts generic Comparable input values. Aggregation result type is R.

    - #### minBy

          public static <I> Aggregator<I,I> minBy(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the min of the input values extracted from the given attributePath and returns the input item containing the minimum value. If multiple items contain the minimum value, any of them is returned. Accepts null input values and null extracted values. Accepts generic Comparable input values.

    - #### bigDecimalSum

          public static <I> Aggregator<I,BigDecimal> bigDecimalSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigDecimalSum

          public static <I> Aggregator<I,BigDecimal> bigDecimalSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only BigDecimal input values. Aggregation result type is BigDecimal.

    - #### bigIntegerSum

          public static <I> Aggregator<I,BigInteger> bigIntegerSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### bigIntegerSum

          public static <I> Aggregator<I,BigInteger> bigIntegerSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values nor null extracted values. Accepts only BigInteger input values. Aggregation result type is BigInteger.

    - #### doubleSum

          public static <I> Aggregator<I,Double> doubleSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### doubleSum

          public static <I> Aggregator<I,Double> doubleSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values. Accepts only Double input values (primitive and boxed). Aggregation result type is Double.

    - #### integerSum

          public static <I> Aggregator<I,Long> integerSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Long.

    - #### integerSum

          public static <I> Aggregator<I,Long> integerSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values. Accepts only Integer input values (primitive and boxed). Aggregation result type is Long.

    - #### longSum

          public static <I> Aggregator<I,Long> longSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### longSum

          public static <I> Aggregator<I,Long> longSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values. Accepts only Long input values (primitive and boxed). Aggregation result type is Long.

    - #### fixedPointSum

          public static <I> Aggregator<I,Long> fixedPointSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts generic Number input values. Aggregation result type is Long.

    - #### fixedPointSum

          public static <I> Aggregator<I,Long> fixedPointSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values. Accepts generic Number input values. Aggregation result type is Long.

    - #### floatingPointSum

          public static <I> Aggregator<I,Double> floatingPointSum()

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values. Does NOT accept null input values. Accepts generic Number input values. Aggregation result type is Double.

    - #### floatingPointSum

          public static <I> Aggregator<I,Double> floatingPointSum(String attributePath)

      Type Parameters:
        `I` - type of the input object.
      Returns:
        an aggregator that calculates the sum of the input values extracted from the given attributePath. Does NOT accept null input values. Accepts generic Number input values. Aggregation result type is Double.

Copyright © 2020. All rights reserved.