psdi.app.recontask.engine

Class ReconExpression

  • java.lang.Object
    • psdi.app.recontask.engine.ReconExpression
    • Field Detail

      • TOKEN_RIGHT_PARENTHESIS

        public static final int TOKEN_RIGHT_PARENTHESIS
        See Also:
        Constant Field Values
      • TOKEN_VALUE

        public static final int TOKEN_VALUE
        a value to compare against in an expression
        See Also:
        Constant Field Values
      • TOKEN_LOWEST_VALUE

        public static final int TOKEN_LOWEST_VALUE
        the lowest numerical value the tag that a valid expression token can have
        See Also:
        Constant Field Values
      • TOKEN_HIGHEST_VALUE

        public static final int TOKEN_HIGHEST_VALUE
        the highest numerical value of the tag that a valid expression token can have
        See Also:
        Constant Field Values
      • validOperators

        public java.util.List validOperators
        the allowed operators
      • rootNode

        protected BinaryTreeNode rootNode
        the root of the compiled binary tree
      • infixTokens

        protected java.util.List infixTokens
        the input expression in infix notation
      • compiled

        protected boolean compiled
        set to true after the expression has been compiled; adding to the input expression will reset the flag
      • expressionTag

        protected java.lang.String expressionTag
        the name of the expression object from th database
    • Constructor Detail

      • ReconExpression

        public ReconExpression(ReconInfo reconInfo)
    • Method Detail

      • setExpressionTag

        public void setExpressionTag(java.lang.String expressionTag)
      • getExpressionTag

        public java.lang.String getExpressionTag()
      • getCompiledExpressionAsString

        public java.lang.String getCompiledExpressionAsString()
      • findOperator

        protected ReconOperator findOperator(int tokenType,
                                             java.lang.String tokenValue,
                                             java.util.List containingExpressionOperators)
                                      throws MXException
        Throws:
        MXException
      • addExpressionToken

        public void addExpressionToken(int tokenType,
                                       java.lang.String tokenValue)
                                throws MXException
        Append a token at the end of the expresion. Will invalidate the expression
        Throws:
        MXException
      • addExpressionToken

        public void addExpressionToken(int tokenType,
                                       java.lang.String tokenValue,
                                       java.lang.String tokenUnit)
                                throws MXException
        Append a token at the end of the expresion. Will invalidate the expression
        Throws:
        MXException
      • prepareAttributeIndexes

        public void prepareAttributeIndexes(ReconValueSet leadingSet,
                                            ReconValueSet subordinateSet)
                                     throws MXException
        Modifies the comparison operators to use indexes into the attribute arrays instead of attribute names - done for performance reasons
        Parameters:
        leadingSet -
        subordinateSet -
        Throws:
        MXException
      • getExpressionTag

        protected java.lang.String getExpressionTag(MboRemote clause)
                                             throws MXException,
                                                    java.rmi.RemoteException
        Overridable to allow subclsasses adapt for eventual attribute name difference
        Parameters:
        clause - the MboRemote
        Returns:
        the expresion tag
        Throws:
        MXException
        java.rmi.RemoteException
      • getSequenceNum

        protected int getSequenceNum(MboRemote clause)
                              throws MXException,
                                     java.rmi.RemoteException
        Overridable to allow subclsasses adapt for eventual attribute name difference
        Parameters:
        clause - the MboRemote
        Returns:
        the sequence number as an integer
        Throws:
        MXException
        java.rmi.RemoteException
      • getOpenParentheses

        protected java.lang.String getOpenParentheses(MboRemote clause)
                                               throws MXException,
                                                      java.rmi.RemoteException
        Overridable to allow subclsasses adapt for eventual attribute name difference
        Parameters:
        clause - the MboRemote
        Returns:
        all the opening parentheses
        Throws:
        MXException
        java.rmi.RemoteException
      • getCloseParentheses

        protected java.lang.String getCloseParentheses(MboRemote clause)
                                                throws MXException,
                                                       java.rmi.RemoteException
        Overridable to allow subclsasses adapt for eventual attribute name difference
        Parameters:
        clause - the MboRemote
        Returns:
        all the closing parentheses
        Throws:
        MXException
        java.rmi.RemoteException
      • getAndOrAttributeName

        protected java.lang.String getAndOrAttributeName()
        Overridable to adapt for eventual attribute name difference
        Returns:
        the attribute name for the logical operator between clauses
      • readExpression

        public void readExpression(MboSetRemote reconLinkSet)
                            throws MXException,
                                   java.rmi.RemoteException
        The reason why this method exisits: It is not possible to sort the MBO set itself, because this code is called to validate the rule. At that point it is not allowed to sort the MBO set, because sort is always carried out by the database
        Throws:
        MXException
        java.rmi.RemoteException
      • readClause

        protected abstract void readClause(MboRemote clause)
                                    throws MXException,
                                           java.rmi.RemoteException
        Throws:
        MXException
        java.rmi.RemoteException
      • readExpression

        protected void readExpression(java.util.List reconLinkSet)
                               throws MXException,
                                      java.rmi.RemoteException
        Coded readExpression to read Values from the MBO Set (srini) Added Validation checks and exception handling (srini) 7/21/04
        Throws:
        MXException
        java.rmi.RemoteException
      • reset

        public void reset()
        Start over
      • processOperatorToken

        public static void processOperatorToken(java.util.Stack operatorStack,
                                                java.util.Stack nodeStack,
                                                ReconExpressionToken currentToken)
                                         throws MXException
        Parameters:
        operatorStack - stack containing operators found so far
        nodeStack - resulting stack where each object is a BinaryTreeNode
        currentToken - the current token expression being processed
        Throws:
        MXException
        See Also:
        for processing step #'s. 2) Token is an operator: a) pop all operators that have equal or higher precedence from the operator stack b) push operators onto result stack c) push current operator onto the operator stack
      • processRightParenthesisToken

        public static void processRightParenthesisToken(java.util.Stack operatorStack,
                                                        java.util.Stack nodeStack)
        Parameters:
        operatorStack - stack containing operators found so far
        nodeStack - resulting stack where each object is a BinaryTreeNode
        See Also:
        for processing step #'s. 4) Token is right parenthesis: a) Pop all operators from operator stack. b) Push onto resulting stack, until a matching left parenthesis found - do not include the pair of matching parentheses
      • processInfixExpression

        public static void processInfixExpression(java.util.Stack operatorStack,
                                                  java.util.Stack nodeStack,
                                                  ReconExpressionToken currentToken)
                                           throws MXException
        Parameters:
        operatorStack - stack containing operators found so far
        nodeStack - resulting stack where each object is a BinaryTreeNode
        currentToken - the current token expression being processed
        Throws:
        MXException
        See Also:
        for processing step #'s.
      • convertInfixToExpressionTree

        protected BinaryTreeNode convertInfixToExpressionTree()
                                                       throws MXException
        Loops through this list of infix expressions from left to right according to the following steps. These steps are based on the generic algorithm of converting an infix expression to a postfix expression. 1) if token is an operand then push it onto the result stack 2) else if token is an operator then pop all operators that have equal or higher precedence from the operator stack push operators onto result stack push current operator onto the operator stack 3) else if token is left parenthesis then push it onto the operator stack 4) else if token is right parenthesis then pop all operators from the operator stack push onto resulting stack, one by one, until a matching left parenthesis is found; do not include left and right parentheses 5) else if remaining tokens in the list then pop off all remaining operators in the operator stack and push onto the result stack end if
        Returns:
        BinaryTreeNode node at the top (root) of the resulting stack
        Throws:
        MXException
      • convertTreeToInfixString

        protected void convertTreeToInfixString(BinaryTreeNode root,
                                                java.lang.StringBuffer ret,
                                                boolean topLevel)
        Traverse the binary tree using a recursive algorithm
        See Also:
        evaluateTree
      • popLinkPush

        protected static void popLinkPush(java.util.Stack operatorStack,
                                          java.util.Stack nodeStack)
        Pop off remaining operator in the operator stack, create a binary tree node, link its children, and push onto the result stack
        Parameters:
        operatorStack - stack containing operators found so far
        nodeStack - resulting stack where each object is a BinaryTreeNode with links to its left and right child nodes
      • walkTreeReplaceAttributeNamesWithIndexes

        protected void walkTreeReplaceAttributeNamesWithIndexes(BinaryTreeNode root,
                                                                ReconValueSet leadingSet,
                                                                ReconValueSet subordinateSet)
        Traverse the binary tree using a recursive algorithm
        See Also:
        evaluateTree
      • getAttributeSet

        public java.util.Set getAttributeSet(boolean getLeftSide,
                                             boolean stripPrefixes)
        Parameters:
        getLeftSide -
        stripPrefixes -
        Returns:
      • getAttributeToUnitMap

        public java.util.Map getAttributeToUnitMap(boolean getLeftSide,
                                                   boolean stripPrefixes)
        Parameters:
        getLeftSide -
        stripPrefixes -
        Returns:
      • walkTreeToGetAttribSet

        protected void walkTreeToGetAttribSet(BinaryTreeNode root,
                                              java.util.Set attribSet,
                                              boolean getLeftSide)
        Recurse the tree to build a set of unique left or right sides
        Parameters:
        root - - the root node of the tree
        attribSet - - output set to be added to
        getLeftSide - When true, get the RIGHT token - because the tree is built backwards
      • walkTreeToGetAttribToUnitMap

        protected void walkTreeToGetAttribToUnitMap(BinaryTreeNode root,
                                                    java.util.Map attributeToUnitMap,
                                                    boolean getLeftSide)
        Recurse the tree to build a map unique left or right sides to their unit names
        Parameters:
        root - - the root node of the tree
        attribMap - - output set to be added to
        getLeftSide - When true, get the RIGHT token - because the tree is built backwards
      • handleLogicalAnd

        protected java.util.List handleLogicalAnd(java.util.List rightResult,
                                                  java.util.List leftResult)
        Parameters:
        rightResult -
        leftResult -
        Returns:
      • handleLogicalOr

        protected java.util.List handleLogicalOr(java.util.List rightResult,
                                                 java.util.List leftResult)
        Parameters:
        rightResult -
        leftResult -