public class NumericExpressionHelper extends BasicHelper
BigDecimals. For the list of supported operators see the
NumericExpressionHelper.Operator enum values, e.g.:
{{numExpr val op="neg" out='It is a negative number!'}}
{{#numExpr val "90" op="gt"}}
val > 90
{{/numExpr}}
{{#numExpr val 10 op="eq"}}
val == 10
{{/numExpr}}
{{#numExpr val1 val2 op="le"}}
val1 <= val2
{{/numExpr}}
{{#numExpr val "1" 2 '3' op="in"}}
val = 1 or val = 2 or val = 3
{{/numExpr}}
It's also possible to specify the default operator (NumericExpressionHelper.Operator.EQ by
default) so that the op param may be ommitted:
{{#gt val1 10}} val1 > 10 {{/gt}}
Sometimes it also makes sense to register the helper with a name derived from
the default operator or even register a helper instance for each operator -
see forEachOperator().
| Modifier and Type | Class and Description |
|---|---|
static class |
NumericExpressionHelper.Operator |
HELPER_TAG_TYPESconfiguration| Constructor and Description |
|---|
NumericExpressionHelper() |
NumericExpressionHelper(NumericExpressionHelper.Operator defaultOperator) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Options options)
Execute the helper.
|
static HelpersBuilder |
forEachOperator()
Enum.toString() is used as the helper name. |
static void |
forEachOperator(BiConsumer<String,Helper> consumer)
Invokes the specified consumer for all operators.
|
static HelpersBuilder |
forEachOperator(HelpersBuilder builder) |
void |
validate(HelperDefinition definition)
Helper should validate the tag definition (e.g. number of parameters)
during compilation and fail fast if necessary.
|
allowedTagTypes, getRequiredHashKeys, getSupportedHashKeys, numberOfRequiredHashEntries, numberOfRequiredParametersappend, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic NumericExpressionHelper()
public NumericExpressionHelper(NumericExpressionHelper.Operator defaultOperator)
defaultOperator - public static HelpersBuilder forEachOperator()
Enum.toString() is used as the helper name.NumericExpressionHelper instance
registered for each NumericExpressionHelper.Operatorpublic static HelpersBuilder forEachOperator(HelpersBuilder builder)
builder - NumericExpressionHelper instance
registered for each NumericExpressionHelper.Operatorpublic static void forEachOperator(BiConsumer<String,Helper> consumer)
Enum.toString()
is used as the first argument and the corresponding
NumericExpressionHelper instance as the second argument.consumer - public void execute(Options options)
Helperpublic void validate(HelperDefinition definition)
HelperMustacheException with code
MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE should be
thrown in case of validation failure occurs.validate in interface Helpervalidate in class BasicHelperCopyright © 2017. All rights reserved.