|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.shiwa.fgi.iwir.condition.ConditionNode
public class ConditionNode
The Class CondirtionNode provides the data structure and methods to create and evaluate a condition AST. The following EBNF-Grammar defines a condition:
CONDITION := CONJUNCTION {or CONJUNCTION} CONJUNCTION := EQUATION {and EQUATION} EQUATION := RELATION {EQOP RELATION} RELATION := FACTPR {COMPOP FACTOR} FACTOR := not FACTOR | (CONDITION) | STRING | PORT | integer | double | bool COMPOP := > | >= | < | <= EQUOP := != | = STRING := "string" PORT := stringThe preference is not >> > | >= | < | <= >> != | = >> and >> or . We use blank and parenthesis as delimiter. For example 3=3 is invalid. (3 < 4)> 3 is valid. A node has a special token type. It is either an operator or a value type. Depending of the node type, values and children are set. Every binary operation has a left and right child. The unary operator not have only a left child. Parenthesis are construct as follows: The parent node contains ConditionToken.LP and child is set as left child. If the type of a node is for example Token.INT, then the attribute num is set and getNum() returns the corresponding integer value. Other value attributes return null.
Constructor Summary | |
---|---|
ConditionNode(java.lang.Boolean bool)
Instantiates a new node with the given Boolean. |
|
ConditionNode(ConditionNode node)
Returns a copy. |
|
ConditionNode(ConditionToken op)
Instantiates a new node with the given Operator. |
|
ConditionNode(ConditionToken type,
java.lang.String string)
Instantiates a new node with the given String. |
|
ConditionNode(java.lang.Double dob)
Instantiates a new node with the given Double. |
|
ConditionNode(java.lang.Integer num)
Instantiates a new node with the given Integer. |
Method Summary | |
---|---|
static ConditionNode |
createAST(java.lang.String condition)
Creates the AST from the given condition string. |
static boolean |
evalNode(ConditionNode n)
Evaluates an AST and returns a boolean value. |
static java.util.List<ConditionNode> |
flatten(ConditionNode node)
Flattens the AST and returning a list of nodes. |
java.lang.Boolean |
getBool()
Gets the boolean value of the node or null if the value is not set. |
static java.lang.String |
getCondition(ConditionNode n)
Gets the string representation of a condition AST. |
java.lang.Double |
getDob()
Gets the double value of the node or null if the value is not set. |
ConditionNode |
getLeft()
Gets the left subtree of the node or null if the value is not set. |
java.lang.Integer |
getNum()
Gets the int value of the node or null if the value is not set. |
ConditionToken |
getOp()
Gets the current operation or null if the operation is not set. |
java.lang.String |
getPort()
Gets the port or null if the value is not set. |
ConditionNode |
getRight()
Gets the right subtree of the node or null if the value is not set. |
java.lang.String |
getString()
Gets the string value of the node or null if the value is not set. |
static boolean |
isLeaf(ConditionNode n)
Checks if the node is a leaf node. |
static void |
printCondition(ConditionNode n)
Prints the condition string from an AST. |
static void |
printInOrder(ConditionNode n)
Prints the AST in order. |
static void |
printPreOrder(ConditionNode n)
Prints the AST pre order. |
void |
setBool(java.lang.Boolean b)
Sets the boolean value. |
void |
setDob(java.lang.Double d)
Sets the double value. |
void |
setLeft(ConditionNode left)
Sets the left subtree of a node. |
void |
setNum(java.lang.Integer i)
Sets the int value. |
void |
setPort(java.lang.String p)
Sets the port value. |
void |
setRight(ConditionNode right)
Sets the right subtree of a node. |
void |
setString(java.lang.String s)
Sets the string value. |
static java.util.List<ConditionNode> |
split(ConditionNode node,
ConditionToken token)
Split. |
java.lang.String |
toString()
Returns the string representation of an AST. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ConditionNode(ConditionToken op)
op
- the operator of the nodepublic ConditionNode(java.lang.Integer num)
num
- the int value of the nodepublic ConditionNode(java.lang.Double dob)
dob
- the double value of the nodepublic ConditionNode(java.lang.Boolean bool)
bool
- the boolean value of the nodepublic ConditionNode(ConditionToken type, java.lang.String string)
type
- the typestring
- the string value of the nodepublic ConditionNode(ConditionNode node)
node
- the nodeMethod Detail |
---|
public static ConditionNode createAST(java.lang.String condition)
condition
- the condition to parse
public static java.util.List<ConditionNode> flatten(ConditionNode node)
node
- the node
public static java.util.List<ConditionNode> split(ConditionNode node, ConditionToken token)
node
- the nodetoken
- the token
public static void printInOrder(ConditionNode n)
n
- the root node of the ASTpublic static void printPreOrder(ConditionNode n)
n
- the root node of the ASTpublic static java.lang.String getCondition(ConditionNode n)
n
- the root node
public static void printCondition(ConditionNode n)
n
- the root node of the ASTpublic java.lang.String toString()
toString
in class java.lang.Object
getCondition(ConditionNode)
public ConditionToken getOp()
public java.lang.Integer getNum()
public void setNum(java.lang.Integer i)
i
- the new int valuepublic java.lang.Double getDob()
public void setDob(java.lang.Double d)
d
- the new double valuepublic java.lang.Boolean getBool()
public void setBool(java.lang.Boolean b)
b
- the new boolean valuepublic java.lang.String getString()
public void setString(java.lang.String s)
s
- the new string valuepublic ConditionNode getLeft()
public ConditionNode getRight()
public java.lang.String getPort()
public void setPort(java.lang.String p)
p
- the new string valuepublic static boolean isLeaf(ConditionNode n)
n
- the node to check
public void setLeft(ConditionNode left)
left
- the new left subtreepublic void setRight(ConditionNode right)
right
- the new right subtreepublic static boolean evalNode(ConditionNode n)
n
- the root node
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |