org.kuali.student.common.ui.client.widgets.table
Class ExpressionParser

java.lang.Object
  extended by org.kuali.student.common.ui.client.widgets.table.ExpressionParser

public class ExpressionParser
extends Object

This is the parser for boolean expression. It checks the error, creates the Reverse Polish notation, merge the binary tree, sort the nodes.


Field Summary
private  List<String> errorMessageList
          Error messages are stored in a list
 
Constructor Summary
ExpressionParser()
           
 
Method Summary
private  Node<Token> binaryTreeFromRPN(List<Node<Token>> rpnList)
          Build the binary tree from list of tokens
private  void checkAnd(List<Token> tokenList, int currentIndex)
           
private  void checkCondition(List<Token> tokenList, int currentIndex)
           
private  void checkEndParenthesis(List<Token> tokenList, int currentIndex)
           
private  void checkOr(List<Token> tokenList, int currentIndex)
           
private  void checkStartParenthesis(List<Token> tokenList, int currentIndex)
           
private  int countToken(List<Token> tokenList, int type)
           
private  void errorCheck(List<Token> tokenList)
           
private  int findNodeIndex(List<Node<Token>> nodeList, int type)
           
private static Node getDeeperNode(List<Node> nodeList)
           
 List<String> getErrorMessage()
          It returns all error messages
static String getExpressionString(Node root)
          Create the boolean expression from tree
private  List<Node<Token>> getRPN(List<Node<Token>> nodeList)
          If higher push to stack, else pop till less than or equal, add to list push to stack if ( push to stack if ) pop to list till (.
private  List<Token> getTokenList(List<String> tokenValueList)
           
private  List<String> getTokenValue(String expression)
           
 boolean hasError()
          After parsing, it tells if the expression has error.
private  boolean hasParenthesis(List<Node<Token>> nodeList)
           
private  int indexInInputTokenList(Token token, List<Token> list)
          Get the index of a token in the token list
static Node<Token> mergeBinaryTree(Node<Token> binaryTree)
          Merge the binary tree.
private  Node<Token> orderLeafChildren(Node<Token> binaryTree, List<Token> tokenList)
          Order the leaf children
private  Node<Token> orderNonLeafChildren(Node<Token> binaryTree, List<Token> tokenList)
          Order the nonleaf children
private static boolean parentEqualsGrandParent(Node<Token> binaryTree)
           
 Node<Token> parse(String expression)
          Parse the boolean expression
private  void sequeceLeaves(List<Node> leafChildList, List<Token> list)
          Reorder the children
private  void sequeceNonLeaves(List<Node> nonLeafChildList, List<Token> list)
          Order the non leaves
private  List<Node<Token>> toNodeList(List<Token> tokenList)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorMessageList

private List<String> errorMessageList
Error messages are stored in a list

Constructor Detail

ExpressionParser

public ExpressionParser()
Method Detail

hasError

public boolean hasError()
After parsing, it tells if the expression has error.

Returns:
If the input expression has error

getErrorMessage

public List<String> getErrorMessage()
It returns all error messages

Returns:
List of error messages

parse

public Node<Token> parse(String expression)
Parse the boolean expression

Returns:
the tree of input tokens

getExpressionString

public static String getExpressionString(Node root)
Create the boolean expression from tree

Returns:
boolean expression

orderNonLeafChildren

private Node<Token> orderNonLeafChildren(Node<Token> binaryTree,
                                         List<Token> tokenList)
Order the nonleaf children


sequeceNonLeaves

private void sequeceNonLeaves(List<Node> nonLeafChildList,
                              List<Token> list)
Order the non leaves


orderLeafChildren

private Node<Token> orderLeafChildren(Node<Token> binaryTree,
                                      List<Token> tokenList)
Order the leaf children


sequeceLeaves

private void sequeceLeaves(List<Node> leafChildList,
                           List<Token> list)
Reorder the children


indexInInputTokenList

private int indexInInputTokenList(Token token,
                                  List<Token> list)
Get the index of a token in the token list


getDeeperNode

private static Node getDeeperNode(List<Node> nodeList)

mergeBinaryTree

public static Node<Token> mergeBinaryTree(Node<Token> binaryTree)
Merge the binary tree.


parentEqualsGrandParent

private static boolean parentEqualsGrandParent(Node<Token> binaryTree)

binaryTreeFromRPN

private Node<Token> binaryTreeFromRPN(List<Node<Token>> rpnList)
Build the binary tree from list of tokens


getRPN

private List<Node<Token>> getRPN(List<Node<Token>> nodeList)
If higher push to stack, else pop till less than or equal, add to list push to stack if ( push to stack if ) pop to list till (. http://en.wikipedia.org/wiki/Reverse_Polish_notation


findNodeIndex

private int findNodeIndex(List<Node<Token>> nodeList,
                          int type)

hasParenthesis

private boolean hasParenthesis(List<Node<Token>> nodeList)

toNodeList

private List<Node<Token>> toNodeList(List<Token> tokenList)

errorCheck

private void errorCheck(List<Token> tokenList)

countToken

private int countToken(List<Token> tokenList,
                       int type)

checkAnd

private void checkAnd(List<Token> tokenList,
                      int currentIndex)

checkOr

private void checkOr(List<Token> tokenList,
                     int currentIndex)

checkStartParenthesis

private void checkStartParenthesis(List<Token> tokenList,
                                   int currentIndex)

checkEndParenthesis

private void checkEndParenthesis(List<Token> tokenList,
                                 int currentIndex)

checkCondition

private void checkCondition(List<Token> tokenList,
                            int currentIndex)

getTokenList

private List<Token> getTokenList(List<String> tokenValueList)

getTokenValue

private List<String> getTokenValue(String expression)


Copyright © 2007-2011 The Kuali Foundation. All Rights Reserved.