Java String and Mathematical Expression Evaluators

六月ゝ 毕业季﹏ 提交于 2019-12-06 15:01:54

There are a lot of tools out there to evaluate expressions; the correct answer will depend on your exact goals.

Two things that I'd look at:

The answer was a posting on the Jeks forum. I got an answer from Manu. I thought it was not active especially as I could not register on it - but that got sorted.

But if anyone has the same problem then the following lines of code will get it working:

ExpressionParser parser; // we did have = new ExpressionParser(new JeksExpressionSyntax(), null);
JeksInterpreter interpreter; // 

And to create the interpreter:

interpreter = new JeksInterpreter() {

      @Override
      public Object getBinaryOperatorValue (Object binaryOperatorKey, Object param1, Object param2)
      {
        // Only functions may take a cell set as parameter
        if ( param1 instanceof JeksCellSet || param2 instanceof JeksCellSet)
          throw new IllegalArgumentException ();
        // Enabled comparison between any type supported by Jeks
        else if (binaryOperatorKey.equals (JeksExpressionSyntax.OPERATOR_EQUAL))
          return param1 != null && param1.equals (param2)
                   ? Boolean.TRUE : Boolean.FALSE;
        // Enabled comparison between any type supported by Jeks
        else if (binaryOperatorKey.equals (JeksExpressionSyntax.OPERATOR_DIFFERENT))
          return param1 != null && param1.equals (param2) ? Boolean.FALSE : Boolean.TRUE;
        else
          return super.getBinaryOperatorValue (binaryOperatorKey, param1, param2);
      }
    };

    parser = new ExpressionParser(new JeksExpressionSyntax(), null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!