Class QueryTree

java.lang.Object
dev.roanh.gmark.ast.QueryTree

public class QueryTree extends Object
Representation of an Abstract Syntax Tree (AST) for queries.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final QueryFragment
    The query fragment this query tree node was derived from.
    private final QueryTree
    For unary and binary operations the left input argument, for atoms null.
    private final QueryTree
    For binary operations the right input argument, for unary operations and atoms null.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    QueryTree(QueryTree left, QueryTree right, QueryFragment fragment)
    Constructs a new query tree from the given input.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the left child node of this AST node if any.
    Gets the operation represented by this AST node.
    If the operation for this AST node is OperationType.EDGE, returns the edge label or predicate associated with edge at this AST node.
    Gets the right child node of this AST node if any.
    boolean
    Checks if the operation for this AST node is a binary operation, meaning it takes exactly two operands and has exactly two child nodes in the query AST.
    boolean
    Checks if this AST node is a leaf node.
    boolean
    Checks if the operation for this AST node is a unary operation, meaning it takes exactly one operand and has exactly one child node in the query AST.
    static QueryTree
    Constructs an AST node for a query fragment representing an atomic operation.
    static QueryTree
    ofBinary(QueryTree left, QueryTree right, QueryFragment fragment)
    Constructs an AST node for a query fragment representing a binary operation.
    static QueryTree
    ofUnary(QueryTree left, QueryFragment fragment)
    Constructs an AST node for a query fragment representing a unary operation.
    Returns a stream over all the AST nodes in the sub-tree rooted at this AST node, including this AST node itself.
     
    private void
    Writes this AST in list from to the given indent writer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • left

      private final QueryTree left
      For unary and binary operations the left input argument, for atoms null.
    • fragment

      private final QueryFragment fragment
      The query fragment this query tree node was derived from.
  • Constructor Details

    • QueryTree

      private QueryTree(QueryTree left, QueryTree right, QueryFragment fragment)
      Constructs a new query tree from the given input.
      Parameters:
      left - The left input argument for unary and binary operations.
      right - The right input argument binary operations.
      fragment - The query fragment this AST node was derived from.
  • Method Details

    • isLeaf

      public boolean isLeaf()
      Checks if this AST node is a leaf node. This implies that the operation for this AST node is an atom and that this node has no child nodes or inputs.
      Returns:
      True if this AST node is a leaf node.
      See Also:
    • isUnary

      public boolean isUnary()
      Checks if the operation for this AST node is a unary operation, meaning it takes exactly one operand and has exactly one child node in the query AST. The child node of the input for the operation in this node is given by getLeft().
      Returns:
      True if the operation for this AST node is unary.
      See Also:
    • isBinary

      public boolean isBinary()
      Checks if the operation for this AST node is a binary operation, meaning it takes exactly two operands and has exactly two child nodes in the query AST. The two inputs for the operation in this node are given in order by getLeft() and getRight().
      Returns:
      True if the operation for this AST node is binary.
      See Also:
    • getOperation

      public OperationType getOperation()
      Gets the operation represented by this AST node.
      Returns:
      The operation for this AST node.
      See Also:
    • getPredicate

      public Predicate getPredicate() throws IllegalStateException
      If the operation for this AST node is OperationType.EDGE, returns the edge label or predicate associated with edge at this AST node.
      Returns:
      The label at this AST node.
      Throws:
      IllegalStateException - When the operation for this AST node is not equal to OperationType.EDGE.
      See Also:
    • getLeft

      public QueryTree getLeft()
      Gets the left child node of this AST node if any. This child node is only present if the operation for this AST node is unary or binary and for binary operation represents the first input argument.
      Returns:
      The left child node of this AST node or null if this node is a leaf.
      See Also:
    • getRight

      public QueryTree getRight()
      Gets the right child node of this AST node if any. This child node is only present if the operation for this AST node is binary and represents the second input argument.
      Returns:
      The right child node of this AST node of null if the operation for this node is not binary.
      See Also:
    • stream

      public Stream<QueryTree> stream()
      Returns a stream over all the AST nodes in the sub-tree rooted at this AST node, including this AST node itself. The tree will be traversed in a top down manner with left child nodes appearing before right child nodes.
      Returns:
      A stream over all AST nodes in the sub-tree rooted at this AST node.
    • writeAST

      private void writeAST(IndentWriter writer)
      Writes this AST in list from to the given indent writer.
      Parameters:
      writer - The indent writer to write to.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • ofAtom

      public static QueryTree ofAtom(QueryFragment fragment)
      Constructs an AST node for a query fragment representing an atomic operation.
      Parameters:
      fragment - The query fragment.
      Returns:
      The AST for the given query fragment.
      See Also:
    • ofUnary

      public static QueryTree ofUnary(QueryTree left, QueryFragment fragment)
      Constructs an AST node for a query fragment representing a unary operation.
      Parameters:
      left - The AST representing the input to the operation in the given query fragment.
      fragment - The query fragment.
      Returns:
      The AST for the given query fragment.
      See Also:
    • ofBinary

      public static QueryTree ofBinary(QueryTree left, QueryTree right, QueryFragment fragment)
      Constructs an AST node for a query fragment representing a binary operation.
      Parameters:
      left - The AST representing the first input argument to the operation in the given query fragment.
      right - The AST representing the second input argument to the operation in the given query fragment.
      fragment - The query fragment.
      Returns:
      The AST for the given query fragment.
      See Also: