public class NumericExpressionHelper extends BasicHelper
BigDecimal
s. 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_TYPES
configuration
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, numberOfRequiredParameters
append, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariable
checkNotInitialized, init
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfigurationKeys, init
public 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.Operator
public static HelpersBuilder forEachOperator(HelpersBuilder builder)
builder
- NumericExpressionHelper
instance
registered for each NumericExpressionHelper.Operator
public 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)
Helper
public void validate(HelperDefinition definition)
Helper
MustacheException
with code
MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE
should be
thrown in case of validation failure occurs.validate
in interface Helper
validate
in class BasicHelper
Copyright © 2017. All rights reserved.