Class JBBPExpressionEvaluator

java.lang.Object
com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluator
All Implemented Interfaces:
JBBPIntegerValueEvaluator, Serializable

public final class JBBPExpressionEvaluator extends Object implements JBBPIntegerValueEvaluator
The Class implements an evaluator which can calculate an expression.
Since:
1.0
See Also:
  • 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 null
      namedFields - a named field info list, must not be null
      compiledData - 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

      public static boolean hasExpressionOperators(String str)
      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:
      eval in interface JBBPIntegerValueEvaluator
      Parameters:
      inStream - the input stream of data, must not be null
      currentCompiledBlockOffset - the current offset inside the compiled JBBP script
      compiledBlockData - the compiled JBBP script, must not be null
      fieldMap - 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: JBBPIntegerValueEvaluator
      Visit all expression items
      Specified by:
      visitItems in interface JBBPIntegerValueEvaluator
      Parameters:
      block - the compiled block contains value, must not be null
      currentCompiledBlockOffset - the offset of the data in the compiled block
      visitor - the visitor to visit items, must not be null
    • toString

      public String toString()
      Overrides:
      toString in class Object