org.shiwa.fgi.iwir.condition
Class ConditionAST

java.lang.Object
  extended by org.shiwa.fgi.iwir.condition.ConditionAST

public final class ConditionAST
extends java.lang.Object

The Class AST provides the most important methods for creating and evaluating an IWIR condition AST.


Method Summary
static ConditionNode createAndOp(ConditionNode left, ConditionNode right)
          Creates an a AND (and) operation.
static ConditionNode createAST(java.lang.String condition)
          Creates the AST from the given condition.
static ConditionNode createBoolOp(boolean b)
          Creates a bool op.
static ConditionNode createDoubleNode(double d)
          Creates a double node.
static ConditionNode createEqOp(ConditionNode left, ConditionNode right)
          Creates an a EQ (=) operation.
static ConditionNode createGteOp(ConditionNode left, ConditionNode right)
          Creates an a GTE (>=) operation.
static ConditionNode createGtOp(ConditionNode left, ConditionNode right)
          Creates an a GT (>) operation.
static ConditionNode createIntNode(int n)
          Creates a int node.
static ConditionNode createLteOp(ConditionNode left, ConditionNode right)
          Creates an a LTE (<=) operation.
static ConditionNode createLtOp(ConditionNode left, ConditionNode right)
          Creates an a LT (<) operation.
static ConditionNode createNeqOp(ConditionNode left, ConditionNode right)
          Creates an a NEQ (!=) operation.
static ConditionNode createNotOp(ConditionNode left)
          Creates an a NOT (not) operation.
static ConditionNode createOrOp(ConditionNode left, ConditionNode right)
          Creates an a OR (or) operation.
static ConditionNode createParenOp(ConditionNode left)
          Parenthesizes a condition (cond) operation.
static ConditionNode createPortNode(java.lang.String s)
          Creates a port node.
static ConditionNode createStringNode(java.lang.String s)
          Creates a string node.
static boolean evalAST(ConditionNode root)
          Evaluates an AST.
static boolean evalCondition(AbstractTask t)
          Evaluates a condition from a given task.
static java.lang.String getConditionString(ConditionNode root)
          Gets the condition string from a given AST.
static boolean isBoolean(java.lang.String s)
          Checks if the string matches the boolean pattern.
static boolean isDouble(java.lang.String s)
          Checks if the string matches the double pattern.
static boolean isInteger(java.lang.String s)
          Checks if the string matches the integer pattern.
static boolean isLeaf(ConditionNode n)
          Checks if a given node is a leaf.
static boolean isLoopPort(java.lang.String s)
          Checks if the string matches the loopPort/{from/to/step} pattern.
static boolean isOperator(ConditionNode n)
          Checks if a given node is an operator.
static boolean isPort(java.lang.String s)
          Checks if the string matches the port pattern.
static boolean isString(java.lang.String s)
          Checks if the given string matches the string pattern.
static ConditionToken parseToken(java.lang.String token)
          Parses a string and returns the corresponding token.
static void printInOrder(ConditionNode root)
          Prints the AST in order.
static java.lang.String tokenToString(ConditionToken token)
          To string returns the string representation of an operand.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseToken

public static ConditionToken parseToken(java.lang.String token)
Parses a string and returns the corresponding token. If the token can not be parsed a ParseException is thrown.

Parameters:
token - the string to parse
Returns:
the corresponding token

isString

public static boolean isString(java.lang.String s)
Checks if the given string matches the string pattern.

Parameters:
s - the string to check
Returns:
true, if the string matches the pattern

isInteger

public static boolean isInteger(java.lang.String s)
Checks if the string matches the integer pattern. Does only check the pattern; not the lower and upper limit.

Parameters:
s - the string to check
Returns:
true, if the string matches the pattern

isDouble

public static boolean isDouble(java.lang.String s)
Checks if the string matches the double pattern. Does only check the pattern; not the lower and upper limit.

Parameters:
s - the string to check
Returns:
true, if the string matches the patttern

isBoolean

public static boolean isBoolean(java.lang.String s)
Checks if the string matches the boolean pattern.

Parameters:
s - the string to check
Returns:
true, if the string matches the pattern

isPort

public static boolean isPort(java.lang.String s)
Checks if the string matches the port pattern.

Parameters:
s - the string to check
Returns:
true, if the string matches the pattern

isLoopPort

public static boolean isLoopPort(java.lang.String s)
Checks if the string matches the loopPort/{from/to/step} pattern.

Parameters:
s - the string to check
Returns:
true, if the string matches the pattern

tokenToString

public static java.lang.String tokenToString(ConditionToken token)
To string returns the string representation of an operand. Non-operand token throw a a ParseException.

Parameters:
token - the token to return
Returns:
the string

createAST

public static ConditionNode createAST(java.lang.String condition)
                               throws ConditionParseException
Creates the AST from the given condition. A ConditionParseException is thrown if condition could not be parsed.

Parameters:
condition - the condition to parse
Returns:
the root node of the AST
Throws:
ConditionParseException

evalAST

public static boolean evalAST(ConditionNode root)
Evaluates an AST.

Parameters:
root - the root node of the AST
Returns:
true, if the evaluation yields true

evalCondition

public static boolean evalCondition(AbstractTask t)
                             throws java.lang.IllegalArgumentException
Evaluates a condition from a given task. Before the values have to be set using task.setPortValue(x). Throws an IllegalArgumentException if task is not a IfTask or WhileTask.

Parameters:
t - the task
Returns:
true, if successful
Throws:
java.lang.IllegalArgumentException

createAndOp

public static ConditionNode createAndOp(ConditionNode left,
                                        ConditionNode right)
Creates an a AND (and) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the node

createOrOp

public static ConditionNode createOrOp(ConditionNode left,
                                       ConditionNode right)
Creates an a OR (or) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the node

createNotOp

public static ConditionNode createNotOp(ConditionNode left)
Creates an a NOT (not) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
Returns:
the node

createParenOp

public static ConditionNode createParenOp(ConditionNode left)
Parenthesizes a condition (cond) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
Returns:
the node

createEqOp

public static ConditionNode createEqOp(ConditionNode left,
                                       ConditionNode right)
Creates an a EQ (=) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createNeqOp

public static ConditionNode createNeqOp(ConditionNode left,
                                        ConditionNode right)
Creates an a NEQ (!=) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createGtOp

public static ConditionNode createGtOp(ConditionNode left,
                                       ConditionNode right)
Creates an a GT (>) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createGteOp

public static ConditionNode createGteOp(ConditionNode left,
                                        ConditionNode right)
Creates an a GTE (>=) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createLtOp

public static ConditionNode createLtOp(ConditionNode left,
                                       ConditionNode right)
Creates an a LT (<) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createLteOp

public static ConditionNode createLteOp(ConditionNode left,
                                        ConditionNode right)
Creates an a LTE (<=) operation. Throws an exception if a node is null.

Parameters:
left - the left subtree
right - the right subtree
Returns:
the root node

createStringNode

public static ConditionNode createStringNode(java.lang.String s)
Creates a string node.

Parameters:
s - the string
Returns:
the node

createPortNode

public static ConditionNode createPortNode(java.lang.String s)
Creates a port node.

Parameters:
s - the portname
Returns:
the node

createIntNode

public static ConditionNode createIntNode(int n)
Creates a int node.

Parameters:
n - the integer
Returns:
the node

createDoubleNode

public static ConditionNode createDoubleNode(double d)
Creates a double node.

Parameters:
d - the double
Returns:
the node

createBoolOp

public static ConditionNode createBoolOp(boolean b)
Creates a bool op.

Parameters:
b - the boolean
Returns:
the node

getConditionString

public static java.lang.String getConditionString(ConditionNode root)
Gets the condition string from a given AST.

Parameters:
root - the root node of the AST.
Returns:
the condition string

printInOrder

public static void printInOrder(ConditionNode root)
Prints the AST in order.

Parameters:
root - the root node of the AST

isOperator

public static boolean isOperator(ConditionNode n)
Checks if a given node is an operator.

Parameters:
n - the node to check
Returns:
true, if node is and operator

isLeaf

public static boolean isLeaf(ConditionNode n)
Checks if a given node is a leaf. Leaf is a node, whose children are null.

Parameters:
n - the node to check
Returns:
true, if the node is a leaf