Fido Alpha 3.2

fido.util
Class BooleanTree

java.lang.Object
  |
  +--fido.util.BooleanTree
All Implemented Interfaces:
java.io.Serializable

public class BooleanTree
extends java.lang.Object
implements java.io.Serializable

This class represents a boolean expression. Example expression: (A = B) & ((C != D) | (E = F)). The BooleanTree contains two types of nodes: BooleanNode and any BooleanTreeNode as a leaf node. The a subclass of BooleanNode, either BooleanAndNode or BooleanOrNode, will join two subtrees by specifying both must be successful (AND), or either one may be successful (OR).

A sample usage would be:

After loading the tree, call getRootNode() which will validate the tree is correct, and return a BooleanTreeNode, which can be used to traverse the tree.

Parenthesis are handled by two calls startGroup() and endGroup().

See Also:
Serialized Form

Constructor Summary
BooleanTree()
          Construct an empty BooleanTree.
 
Method Summary
 void addBooleanAndNode()
          Creates a BooleanAndNode to be inserted into the tree.
 void addBooleanOrNode()
          Creates a BooleanOrNode to be inserted into the tree.
 void addLeafNode(BooleanTreeNode node)
          Add a leaf node to the tree.
 void endGroup()
          Closes a currently open parenthesis group.
 BooleanTreeNode getRootNode()
          After filling the BooleanTree, this call will validate the tree is correct using the validateTree() call, then return the root node of the tree for traversal.
 void startGroup()
          Starts a new parenthesis group.
 void validateTree()
          Used to validate the tree is properly formed: All parenthesis are closed The last boolean node contains a right branch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanTree

public BooleanTree()
Construct an empty BooleanTree.

Method Detail

getRootNode

public BooleanTreeNode getRootNode()
                            throws BooleanSyntaxException
After filling the BooleanTree, this call will validate the tree is correct using the validateTree() call, then return the root node of the tree for traversal.

BooleanSyntaxException
See Also:
validateTree()

addLeafNode

public void addLeafNode(BooleanTreeNode node)
                 throws BooleanSyntaxException
Add a leaf node to the tree.

Parameters:
node - any Object that implements BooleanTreeNode
Throws:
BooleanSyntaxException - Thrown when adding a leaf node immediately after adding a previous leaf node. A leaf node must be the first node, or added after a BooleanNode.
See Also:
BooleanTreeNode

addBooleanAndNode

public void addBooleanAndNode()
                       throws BooleanSyntaxException
Creates a BooleanAndNode to be inserted into the tree. This means that both the left and right branches must evaluate to true.

Throws:
BooleanSyntaxException - Thrown when no nodes are present in the tree. A subclas of BooleanNode cannot be the first node in the tree. For example, the following expression is invalid: & (A = C)
See Also:
BooleanAndNode

addBooleanOrNode

public void addBooleanOrNode()
                      throws BooleanSyntaxException
Creates a BooleanOrNode to be inserted into the tree. This means that both the left or right branches must evaluate to true.

Throws:
BooleanSyntaxException - Thrown when no nodes are present in the tree. A subclas of BooleanNode cannot be the first node in the tree. For example, the following expression is invalid: & (A = C)
See Also:
BooleanOrNode

startGroup

public void startGroup()
Starts a new parenthesis group.


endGroup

public void endGroup()
              throws BooleanSyntaxException
Closes a currently open parenthesis group.

Throws:
BooleanSyntaxException - Thrown if no parenthese groups are open or if a boolean node is the last node in the group.

validateTree

public void validateTree()
                  throws BooleanSyntaxException
Used to validate the tree is properly formed: If any error is found, a BooleanSyntaxException is thrown.

Throws:
BooleanSyntaxException - Thrown if an error in the tree is found. See list above.

Fido Alpha 3.2