Package evaluator

Class ExpressionEvaluator

java.lang.Object
evaluator.ExpressionEvaluator
All Implemented Interfaces:
Evaluator

public class ExpressionEvaluator extends Object implements Evaluator
Implementation of the Evaluator interface
Since:
April 2025
Version:
1.0
Author:
Saptarshi Dey
  • Constructor Details

    • ExpressionEvaluator

      public ExpressionEvaluator()
      Default constructor
    • ExpressionEvaluator

      public ExpressionEvaluator(Map<String,Complex> variables_)
      Parameterised constructor
      Parameters:
      variables_ - Map Object representing variables to be used while evaluating any function
  • Method Details

    • setVariable

      public void setVariable(String variable, Complex value)
      Setter for the variables Map Object for Complex values
      Parameters:
      variable - Name of the variable
      value - Value of th variable
    • setVariable

      public void setVariable(String variable, double value)
      Setter for the variables Map Object for real values
      Parameters:
      variable - Name of the variable
      value - Value of the variable
    • setVariables

      public void setVariables(Map<String,Complex> variables_)
      Setter to set the whole variables Map Object at once
      Parameters:
      variables_ - Map object of all the variables
    • getVariable

      public Complex getVariable(String variable)
      Getter to get individual variables
      Parameters:
      variable - Name of the variable
      Returns:
      Complex number representing the value of the variable
    • removeVariable

      public void removeVariable(String variable)
      Remove a variable from the variables Map Object
      Parameters:
      variable - Name of the variable
    • complexEvaluator

      public Complex complexEvaluator(String equation, boolean verbose) throws Exception
      The function that connects all the modules together and computes the result
      Parameters:
      equation - String repesentation of the equation
      verbose - Whether or not to show the computation
      Returns:
      Resultant Complex number
      Throws:
      Exception
    • evaluateEquation

      public String evaluateEquation(String equation, int precision, boolean verbose) throws Exception
      Wrapper for complexEvaluator function
      Specified by:
      evaluateEquation in interface Evaluator
      Parameters:
      equation - String repesentation of the equation
      precision - Precision of fractional part of the real and imaginary values
      verbose - Whether or not to show the computation
      Returns:
      String value representing the result
      Throws:
      Exception