Class ExpressionAggregationFunction.Builder

java.lang.Object
nz.org.riskscape.engine.function.ExpressionAggregationFunction.Builder
Enclosing class:
ExpressionAggregationFunction

public static class ExpressionAggregationFunction.Builder extends Object

Wee builder to decrease chances of bugs due to mis-assigned constructor args.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • map

      Supply a single arg lambda expression that maps an input value in to an accumulated value that can be reduced. If omitted, an identity expression is used, i.e. no mapping occurs. For a mean function, we can use a mapping expression of value -> {count: 1, total: value}

    • reduce

      Supply a binary arg lambda expression that reduces two mapped values in to one. For example, the expression value + last would be the reduce expression for a sum function. A mean reduction can be expressed like (l, r) -> {count: l.count + r.count, total: l.total + r.total}

    • process

      Supply a single arg lambda expression that maps an accumulated value in to a return value. If omitted, an identity expression is used, e.g. the accumulated value is returned.

      For the mean example, we would process the accumulated value with value -> value.total / value.count

    • identity

      Supply an identity expression for the function. This expression should yield a constant value for when the aggregate function would otherwise yield null, e.g. on an empty set. This value will be coerced to the return type of the function if required, e.g. floating to integer.

    • build