End-user can define condition selections/logical expressions in String like below:
String expression = "((1 OR 2) AND 6 AND (3 OR 4)) AND 5";
- or
String expression = "(1 AND 2 AND 3 AND 4) OR (5 AND 6)";
- or etc...
and the values of 1, 2, 3, ... are pre-calculated stored in a map like {1: true, 2: false, 3: true, ...}
The requirement is to evaluate the above expression with the values stored in the map and get the final output in true/false.
For eg.:
String expression = "(1 AND 2) OR 3";
Map<Integer, Boolean> values = new Map<Integer, Boolean>{1=> true, 2=> false, 3=> true};
System.debug(evaluate(expression, values)); // This should print true
In the above example "(1 AND 2) OR 3" should evaluates to "(true AND false) OR true", which result in final true answer.
I need help in writing the evaluate
method.