Class FormulaInterpreter

java.lang.Object
org.openlca.expressions.FormulaInterpreter

public class FormulaInterpreter extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(String variable, double value)
    Binds the given variable to the given value in the global scope of the interpreter.
    void
    bind(String variable, String expression)
    Binds the given variable to the given expression in the global scope of the interpreter.
    void
    Removes all local scopes and all variable bindings of the global scope from this interpreter.
    createScope(long id)
    Creates a new scope with the given ID in the global scope.
    createScope(long id, Scope parent)
    Creates a new scope with the given ID in the parent scope.
    double
    eval(String expression)
    Evaluates the given expression in the global scope of the interpreter.
    Returns the global scope of the interpreter.
    getOrCreate(long id)
     
    getScope(long id)
    Returns the scope with the given ID or null if no such scope is defined.
    Get the scope for the given ID or the global scope if no such scope exists.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FormulaInterpreter

      public FormulaInterpreter()
  • Method Details

    • clear

      public void clear()
      Removes all local scopes and all variable bindings of the global scope from this interpreter.
    • eval

      public double eval(String expression) throws InterpreterException
      Evaluates the given expression in the global scope of the interpreter.
      Throws:
      InterpreterException
    • bind

      public void bind(String variable, String expression)
      Binds the given variable to the given expression in the global scope of the interpreter.
    • bind

      public void bind(String variable, double value)
      Binds the given variable to the given value in the global scope of the interpreter.
    • getGlobalScope

      public Scope getGlobalScope()
      Returns the global scope of the interpreter.
    • createScope

      public Scope createScope(long id)
      Creates a new scope with the given ID in the global scope.
    • getOrCreate

      public Scope getOrCreate(long id)
    • createScope

      public Scope createScope(long id, Scope parent)
      Creates a new scope with the given ID in the parent scope.
    • getScope

      public Optional<Scope> getScope(long id)
      Returns the scope with the given ID or null if no such scope is defined.
    • getScopeOrGlobal

      public Scope getScopeOrGlobal(long id)
      Get the scope for the given ID or the global scope if no such scope exists.