Class LogicNode

  • All Implemented Interfaces:
    ExpressionNode

    public class LogicNode
    extends java.lang.Object
    implements ExpressionNode
    This class defines a logical expression of nodes. This implementation uses a stack to evaluate its content as to avoid deep recursions when building the parse tree.
    Author:
    Simon Thoresen Hult
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  LogicNode.NodeItem
      Private class to store expression nodes in a stack.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AND  
      static int NOP  
      static int OR  
    • Constructor Summary

      Constructors 
      Constructor Description
      LogicNode()
      Construct an empty logic expression.
    • Constructor Detail

      • LogicNode

        public LogicNode()
        Construct an empty logic expression.
    • Method Detail

      • add

        public LogicNode add​(java.lang.String operator,
                             ExpressionNode node)
        Adds an (operator, node) pair to this expression.
        Parameters:
        operator - The operator that combines the previous with the node given.
        node - The node to add to this.
        Returns:
        This, to allow chaining.
      • getOrdering

        public OrderingSpecification getOrdering​(int order)
        Description copied from interface: ExpressionNode
        If this document selection implies a specific ordering (using the orderdoc scheme), return that specification.
        Specified by:
        getOrdering in interface ExpressionNode
        Parameters:
        order - The order in which we are looking to traverse the ordering (ASCENDING or DESCENDING)
      • evaluate

        public java.lang.Object evaluate​(Context context)
        Description copied from interface: ExpressionNode
        Evaluate the content of this node based on document object, and return that value.
        Specified by:
        evaluate in interface ExpressionNode
        Parameters:
        context - The document to evaluate over.
        Returns:
        The value of this.
      • accept

        public void accept​(Visitor visitor)
        Description copied from interface: ExpressionNode
        Perform visitation of this node.
        Specified by:
        accept in interface ExpressionNode
        Parameters:
        visitor - The visitor that wishes to visit the node.
      • toString

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

        public java.lang.String operatorToString​(int operator)
        Converts the given operator index to a string representation.
        Parameters:
        operator - The operator index to convert.
        Returns:
        The string representation.