-2

I made use of JEP earlier and then realised that it wont fit my case.

On a call to the database/backend, I get a json response, which has a structure as below:

"key": {
"!A & B"
}

And there will be values for A and B like true or false.

I used bpodgursky.jbool_expressions, but do not understand how to substitute values:

 Expression<String> parsedExpression = RuleSet.simplify(ExprParser.parse("!A&B"));
    RuleSet.assign("A", Boolean.TRUE); //THIS IS WRONG

Could anybody help me with the correct library to work on and some sample example to do so?

RCB
  • 479
  • 1
  • 9
  • Maybe this post is helpful: https://stackoverflow.com/questions/12203003/boolean-expression-parser-in-java – happy songs Mar 07 '22 at 14:40
  • 1
    According to the [documentation](https://github.com/bpodgursky/jbool_expressions), you're supposed to pass the expression and a map to `RuleSet.assign`. See under "**Variable Assignment**". Did you read the documentation? – David Conrad Mar 07 '22 at 15:03

1 Answers1

0

You'll need to create it like this.

Expression<String> expression = RuleSet.simplify(ExprParser.parse("!A&B"));
Map<String, Object> keyValue = Map.of("A", false, "B", true);
Expression<String> resolved = RuleSet.assign(expression, keyValue);
System.out.println(resolved); // returns true

Refer this documentation for more clarity on how to use it: https://github.com/bpodgursky/jbool_expressions

Aman
  • 124
  • 1
  • 8