jboolexpr
Class BooleanExpression

java.lang.Object
  extended by jboolexpr.BooleanExpression

public abstract class BooleanExpression
extends java.lang.Object

The main class to evaluate Boolean String Expressions.

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();
}

Author:
Adolfo Sanz De Diego

Method Summary
 boolean booleanValue()
           
static BooleanExpression readLeftToRight(java.lang.String booleanExpression)
          Returns a BooleanExpression that read the Boolean String Expression from left to right.
static BooleanExpression readRightToLeft(java.lang.String booleanExpression)
          Returns a BooleanExpression that read the Boolean String Expression from right to left.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readLeftToRight

public static BooleanExpression readLeftToRight(java.lang.String booleanExpression)
                                         throws MalformedBooleanException
Returns a BooleanExpression that read the Boolean String Expression from left to right.

Parameters:
booleanExpression - The boolean expression to evaluate.
Returns:
A BooleanExpression that read the Boolean String Expression from left to right.
Throws:
MalformedBooleanException - If the supplied boolean expression is malformed.

readRightToLeft

public static BooleanExpression readRightToLeft(java.lang.String booleanExpression)
                                         throws MalformedBooleanException
Returns a BooleanExpression that read the Boolean String Expression from right to left.

Parameters:
booleanExpression - The boolean expression to evaluate.
Returns:
A BooleanExpression that read the Boolean String Expression from right to left.
Throws:
MalformedBooleanException - If the supplied boolean expression is malformed.

booleanValue

public boolean booleanValue()
Returns:
boolean value