Попробуйте это.
static boolean eval(String s, Map<String, Boolean> variables) throws ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
for (Entry<String, Boolean> e : variables.entrySet())
engine.put(e.getKey(), e.getValue());
return (boolean) engine.eval(s.replace("and", "&&").replace("or", "||"));
}
и
boolean result = eval("(A and (B or C))", Map.of("A", true, "B", false, "C", true));
System.out.println(result);
// -> true