Calculator bound to a fixed list of resources, providing MVEL-expression-based filtering and summing for templates. An instance is obtained by calling calc(list) on the Formatter, so it is normally reached from a Velocity or JS template as formatter.calc(someList). Every method evaluates the same MVEL expression once against each resource in the bound list, so cost is proportional to the size of the list.


Methods

eval(String mvelExpr, Object r)

Returns: Object

Evaluates an MVEL expression once, against a single resource as the expression's root context. This is the primitive used internally by sum and filter, evaluating the expression for one item at a time, but it can also be called directly to compute an arbitrary value for a single resource.

ParameterDescription
mvelExprthe MVEL expression to evaluate, in the syntax of the MVEL2 expression language
rthe object made available to the expression as its root context, typically a CommonResource

sum(String mvelExpr)

Returns: BigDecimal

Sums a numeric MVEL expression across every resource in the bound list, rounding the total to a whole number. Equivalent to calling sum(mvelExpr, 0).

ParameterDescription
mvelExprthe MVEL expression to evaluate against each resource, expected to resolve to a number

filter(String mvelExpr)

Returns: ResourceList

Filters the bound list with an MVEL boolean expression, keeping only the resources for which the expression evaluates to true. The expression is evaluated once per item in the list, so cost is proportional to the size of the list.

ParameterDescription
mvelExprthe MVEL boolean expression to test against each resource

sum(String mvelExpr, int decimals)

Returns: BigDecimal

Sums a numeric MVEL expression across every resource in the bound list, rounding the total to the given number of decimal places. Each resource's value is parsed with the Formatter this Calc was created with.

ParameterDescription
mvelExprthe MVEL expression to evaluate against each resource, expected to resolve to a number
decimalsthe number of decimal places to round the total to
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.