Boolean Expression Evaluation in Java

前端 未结 10 1383
-上瘾入骨i
-上瘾入骨i 2020-12-05 16:26

I\'m looking for a relatively simpler (when compared with writing a parser) way to evaluate boolean expressions in Java, and I do not want to use the JEP library.

I

10条回答
  •  清歌不尽
    2020-12-05 16:40

    You could try this library https://github.com/Shy-Ta/expression-evaluator-demo - the read me has a fair number of examples. The library uses java and groovy.

    In addition to supporting this use case, it also supports a lot of other excel like functions. Also, it is very simple to add new functions as demonstrated in the example.

          ExpressionsEvaluator evalExpr = ExpressionsFactory.create("(x > 4 || x < 8 && p > 6)");  
          Map variables = new HashMap();  
          variables.put("x", 100);  
          variables.put("p", 10);
          evalExpr.eval();
    

提交回复
热议问题