Class TreeNode<E>

java.lang.Object
org.neo4j.cypherdsl.core.TreeNode<E>
Type Parameters:
E - the type of each node value

@API(status=EXPERIMENTAL, since="2023.2.0") public final class TreeNode<E> extends Object
A mutable tree structure providing Breadth-first search (aka in-level order traversal) and pre-ordered depth-first search. This class is thread-safe.
Since:
2023.2.0
Author:
Michael J. Simons
  • Method Details

    • from

      public static TreeNode<Visitable> from(Statement statement)
      Creates a tree from a Statement. This allows to visit all elements of statement without implementing custom visitors. The root of the returned tree will always be the statement.
      Parameters:
      statement - the statement that should be represented as a tree
      Returns:
      a tree with the statement as root
    • isRoot

      public boolean isRoot()
      Returns true if this is the root node.
      Returns:
      true if this is the root node
    • getLevel

      public int getLevel()
      Returns the level or the height in this tree in which 0 is the level of the root node.
      Returns:
      the level or the height in this tree
    • getParent

      public TreeNode<E> getParent()
      Returns the parent of this node or null if this is a root node.
      Returns:
      the parent of this node or null if this is a root node
    • getChildren

      public Collection<TreeNode<E>> getChildren()
      Returns an immutable collection of this nodes children.
      Returns:
      an immutable collection of this nodes children
    • getValue

      public E getValue()
      Returns the value of this node.
      Returns:
      the value of this node
    • breadthFirst

      public Iterator<TreeNode<E>> breadthFirst()
      Returns a breadth-first iterator of this node and it's children.
      Returns:
      a breadth-first iterator of this node and it's children
    • preOrder

      public Iterator<TreeNode<E>> preOrder()
      Returns a depth-first, pre-ordered iterator of this node and it's children.
      Returns:
      a depth-first, pre-ordered iterator of this node and it's children
    • printTo

      public void printTo(Consumer<CharSequence> target, Function<TreeNode<E>,String> toString)
      Creates an ASCII representation of this node and its children.
      Parameters:
      target - the target to which to print this tree to
      toString - how to format nodes if this type