-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?

2
  • Maybe this post is helpful: stackoverflow.com/questions/12203003/… Commented Mar 7, 2022 at 14:40
  • 1
    According to the documentation, you're supposed to pass the expression and a map to RuleSet.assign. See under "Variable Assignment". Did you read the documentation? Commented Mar 7, 2022 at 15:03

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.