It is possible to use global constants in expressions.
ConstantsDefinitions
singleton class manage a global constants repository shared by all expresssions. ConstantsDefinitions globals = ConstantsDefinitions.getInstance(); globals.addConstant("myConstant", new Constant(1));By default, the type and structure of a constant is set depending on its value[1] . However, it is possible to specify the type and structure of the constant. For example:
ConstantsDefinitions globals = ConstantsDefinitions.getInstance(); globals.addConstant("myConstant", new Constant(1, ExpressionType.TYPE_FLOAT));Note that as for variables, global constants are shared by all expressions.
ConstantsDefinitions globals = ConstantsDefinitions.getInstance(); globals.addConstant("myConstant", new Constant(1)); Equation equation = ExpressionJ.parse("myConstant+2"); Objet value = equation.eval();The result of value will be 3.
Equation equation = ExpressionJ.parse("const a = 2; return a + 1"); Object result = equation.eval(); // the result is 3
Copyright 2018 Herve Girod. All Rights Reserved