Java String Evaluators and Math Expressions

We are currently using the Jeks parser to evaluate expressions. I see no way to evaluate string expressions with it - for example:

IF ("Test 1" = "Test 2")

Is there anything that can evaluate string and math expressions in Java? Preferably free or open source.

Thanks for any help

Andez

+1
source share
2 answers

The answer was posted on the Jeks forum. I received a response from Manu. I thought it was inactive because I could not register on it, but it is sorted.

But if someone has the same problem, then the following lines of code will work:

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

And to create an 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); 
0
source

There are many tools for evaluating expressions; The correct answer will depend on your exact goals.

Two things that I would look at:

+1
source

Source: https://habr.com/ru/post/913515/


All Articles