User1512
User1512

Reputation: 15

Evaluating Logical Operations AND, OR, NOT dynamically in Java

I have a requirement to execute dynamic expressions for the input data (Map) using Java Code. For Example,

Condition -

EmployeeShift = 'General' AND (EmployeeType = 'CONTRACT' OR Designation IN 'ADMIN')

This expression will be passed on as string variable and with this I have to evaluate my input data which comes at run time. So I'm looking for a parser to parse the condition.

Using the answer of @Tagir Valeev from - the stack over flow's post I was able to parse AND, OR operations. But I'm not sure how to extend it for NOT operation. I'm expecting something to work like below where the expression checks for combined NOT operation for EmployeeType and Designation, rather than checking for each variable.

EmployeeShift = 'General' AND NOT(EmployeeType = 'CONTRACT' OR Designation IN 'ADMIN')

Any example or leads on how to do will be of huge help. Thanks in Advance.

Upvotes: 0

Views: 144

Answers (0)

Related Questions