Class JBBPExpressionEvaluator
java.lang.Object
com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluator
- All Implemented Interfaces:
JBBPIntegerValueEvaluator,Serializable
The Class implements an evaluator which can calculate an expression.
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJBBPExpressionEvaluator(String expression, List<JBBPNamedFieldInfo> namedFields, byte[] compiledData) The Constructor. -
Method Summary
Modifier and TypeMethodDescriptioninteval(JBBPBitInputStream inStream, int currentCompiledBlockOffset, JBBPCompiledBlock compiledBlockData, JBBPNamedNumericFieldMap fieldMap) Evaluate the expression.intGet the max stack depth needed for the expression.static booleanCheck that a string has a char of operators.toString()voidvisitItems(JBBPCompiledBlock block, int currentCompiledBlockOffset, ExpressionEvaluatorVisitor visitor) Visit all expression items
-
Constructor Details
-
JBBPExpressionEvaluator
public JBBPExpressionEvaluator(String expression, List<JBBPNamedFieldInfo> namedFields, byte[] compiledData) The Constructor. It makes compilation an expression into internal representation.- Parameters:
expression- a source expression, must not be nullnamedFields- a named field info list, must not be nullcompiledData- the current compiled data block of JBBP parent script for the expression, must not be null- Throws:
JBBPCompilationException- if any problem in compilation
-
-
Method Details
-
hasExpressionOperators
Check that a string has a char of operators.- Parameters:
str- a string to be checked, must not be null- Returns:
- true if the string contains a char of an operator, false otherwise
-
getMaxStackDepth
public int getMaxStackDepth()Get the max stack depth needed for the expression.- Returns:
- max stack depth for expression
- Since:
- 1.2.1
-
eval
public int eval(JBBPBitInputStream inStream, int currentCompiledBlockOffset, JBBPCompiledBlock compiledBlockData, JBBPNamedNumericFieldMap fieldMap) Evaluate the expression.- Specified by:
evalin interfaceJBBPIntegerValueEvaluator- Parameters:
inStream- the input stream of data, must not be nullcurrentCompiledBlockOffset- the current offset inside the compiled JBBP scriptcompiledBlockData- the compiled JBBP script, must not be nullfieldMap- the named field info map, must not be null- Returns:
- calculated integer result of the expression
- Throws:
JBBPEvalException- if there is any problem during processing
-
visitItems
public void visitItems(JBBPCompiledBlock block, int currentCompiledBlockOffset, ExpressionEvaluatorVisitor visitor) Description copied from interface:JBBPIntegerValueEvaluatorVisit all expression items- Specified by:
visitItemsin interfaceJBBPIntegerValueEvaluator- Parameters:
block- the compiled block contains value, must not be nullcurrentCompiledBlockOffset- the offset of the data in the compiled blockvisitor- the visitor to visit items, must not be null
-
toString
-