org.gusdb.wdk.model
Class BooleanQuestionNode

java.lang.Object
  extended by org.gusdb.wdk.model.BooleanQuestionNode

public class BooleanQuestionNode
extends java.lang.Object

Represents a Question in boolean context. A boolean Question is defined as such by having a BooleanQuery as its Query. Can take one of two forms: 1. Representing a boolean Question and its two boolean operand Questions. The operands can also be boolean Questions so using this class one can create a large tree of recursive boolean Questions. 2. Representing a normal Question that is not itself boolean but is the operand for its parent boolean Question. This is a leaf Question in a boolean Question tree and its pointers to boolean operands are null values. Also recursively sets operand Answers as parameter values for boolean Questions. Created: Fri 22 October 12:00:00 2004 EST


Constructor Summary
BooleanQuestionNode(Question q, BooleanQuestionNode parent)
          Constructor for a BooleanQuestionNode representing a leaf in a boolean Query tree containing a Question that is not boolean.
BooleanQuestionNode(Question q, BooleanQuestionNode firstChild, BooleanQuestionNode secondChild, BooleanQuestionNode parent)
          Constructor for a BooleanQuestionNode representing a boolean Question.
 
Method Summary
static BooleanQuestionNode combine(BooleanQuestionNode firstChild, BooleanQuestionNode secondChild, java.lang.String operator, WdkModel model, java.util.Map<java.lang.String,java.lang.String> operatorMap)
           
 BooleanQuestionNode find(java.lang.String nodeId)
          Recursive method to find a node in the tree.
 BooleanQuestionNode getFirstChild()
           
 BooleanQuestionNode getParent()
           
 Question getQuestion()
           
 BooleanQuestionNode getSecondChild()
           
 java.lang.String getType()
          The type of a BooleanQuestionNode is defined as the RecordClassSet name of the RecordClass.
 java.util.Hashtable getValues()
           
 BooleanQuestionNode grow(BooleanQuestionNode newSecondChild, java.lang.String operator, WdkModel model, java.util.Map<java.lang.String,java.lang.String> operatorMap)
          This method can only be performed on a leaf node and assumes that none of the nodes in the tree has had any parameter values set yet.
 boolean isFirstChild()
           
 boolean isLeaf()
           
 boolean isRoot()
          A BooleanQuestionNode is root if and only if the parent of it is null
 Answer makeAnswer(int startIndex, int endIndex)
          Recursive method that traverses bqn and sets its values, which may be either normal query values if the node is a leaf or the Answers of its operands if the node is a boolean Question.
 void setValues(java.util.Hashtable values)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BooleanQuestionNode

public BooleanQuestionNode(Question q,
                           BooleanQuestionNode firstChild,
                           BooleanQuestionNode secondChild,
                           BooleanQuestionNode parent)
Constructor for a BooleanQuestionNode representing a boolean Question.


BooleanQuestionNode

public BooleanQuestionNode(Question q,
                           BooleanQuestionNode parent)
Constructor for a BooleanQuestionNode representing a leaf in a boolean Query tree containing a Question that is not boolean.

Parameters:
parent - If the supplied parent is null; that implies that this node represents a single-node tree.
Method Detail

getQuestion

public Question getQuestion()

getFirstChild

public BooleanQuestionNode getFirstChild()

getSecondChild

public BooleanQuestionNode getSecondChild()

getParent

public BooleanQuestionNode getParent()

isFirstChild

public boolean isFirstChild()

grow

public BooleanQuestionNode grow(BooleanQuestionNode newSecondChild,
                                java.lang.String operator,
                                WdkModel model,
                                java.util.Map<java.lang.String,java.lang.String> operatorMap)
                         throws WdkModelException,
                                WdkUserException
This method can only be performed on a leaf node and assumes that none of the nodes in the tree has had any parameter values set yet.

Throws:
WdkUserException
WdkModelException

combine

public static BooleanQuestionNode combine(BooleanQuestionNode firstChild,
                                          BooleanQuestionNode secondChild,
                                          java.lang.String operator,
                                          WdkModel model,
                                          java.util.Map<java.lang.String,java.lang.String> operatorMap)
                                   throws WdkModelException,
                                          WdkUserException
Throws:
WdkModelException
WdkUserException

find

public BooleanQuestionNode find(java.lang.String nodeId)
                         throws WdkModelException
Recursive method to find a node in the tree.

Parameters:
nodeId - Binary number representing path to take to find node. The number is read left to right. A 1 in the number will traverse to the left child and a 0 in the number will traverse to the right. When the end of the number is reached, the current node is returned.
Returns:
the BooleanQuestionNode which is being sought.
Throws:
WdkModelException

makeAnswer

public Answer makeAnswer(int startIndex,
                         int endIndex)
                  throws WdkUserException,
                         WdkModelException
Recursive method that traverses bqn and sets its values, which may be either normal query values if the node is a leaf or the Answers of its operands if the node is a boolean Question. The method is recursively called on each of the operands if the node is a boolean Question.

Returns:
the Answer of bqn. The answer should not be used as the answer returned by the top (recursive initializer) node; that should be retrieved by calling makeAnswer() on that node's Question after running this method.
Throws:
WdkUserException
WdkModelException

isLeaf

public boolean isLeaf()
Returns:
whether the node is a leaf in a boolean Question tree; that is, if it is a normal Question without a Boolean Query as its Query.

setValues

public void setValues(java.util.Hashtable values)

getValues

public java.util.Hashtable getValues()

getType

public java.lang.String getType()
The type of a BooleanQuestionNode is defined as the RecordClassSet name of the RecordClass. The type is used when combining two BooleanQuestionNode, and only nodes of the same type can be combined together.

Returns:
get the type of a boolean question node

isRoot

public boolean isRoot()
A BooleanQuestionNode is root if and only if the parent of it is null

Returns:
returns true if the BooleanQuestionNode is root.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object