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
    • getLevel

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

      public TreeNode<E> getParent()
      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
    • getValue

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

      public Iterator<TreeNode<E>> breadthFirst()
      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
    • 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