|
Example 1: read the Boolean String Expression from the left to the right.
String strBoolExpr = "!true&&false||true";
BooleanExpression boolExpr = null;
try {
boolExpr = BooleanExpression.readLeftToRight(strBoolExpr);
boolean bool = boolExpr.booleanValue();
// bool == true
System.out.println(boolExpr.toString() + " == " + bool);
// (((!true)&&false)||true) == true
} catch (MalformedBooleanException e) {
e.printStackTrace();
}
Example 2: read the Boolean String Expression from the right to the left.
String strBoolExpr = "!true&&false||true";
BooleanExpression boolExpr = null;
try {
boolExpr = BooleanExpression.readRightToLeft(strBoolExpr);
boolean bool = boolExpr.booleanValue();
// bool == false
System.out.println(boolExpr.toString() + " == " + bool);
// (!(true&&(false||true))) == false
} catch (MalformedBooleanException e) {
e.printStackTrace();
}
|