Class NodeTraverser


  • @PublicApi
    public class NodeTraverser
    extends java.lang.Object
    Lets you traverse a Node tree.
    • Constructor Detail

      • NodeTraverser

        public NodeTraverser​(java.util.Map<java.lang.Class<?>,​java.lang.Object> rootVars,
                             java.util.function.Function<? super Node,​? extends java.util.List<Node>> getChildren)
      • NodeTraverser

        public NodeTraverser()
    • Method Detail

      • depthFirst

        public java.lang.Object depthFirst​(NodeVisitor nodeVisitor,
                                           Node root)
        depthFirst traversal with a enter/leave phase.
        Parameters:
        nodeVisitor - the visitor of the nodes
        root - the root node
        Returns:
        the accumulation result of this traversal
      • depthFirst

        public java.lang.Object depthFirst​(NodeVisitor nodeVisitor,
                                           java.util.Collection<? extends Node> roots)
        depthFirst traversal with a enter/leave phase.
        Parameters:
        nodeVisitor - the visitor of the nodes
        roots - the root nodes
        Returns:
        the accumulation result of this traversal
      • preOrder

        public java.lang.Object preOrder​(NodeVisitor nodeVisitor,
                                         Node root)
        Version of preOrder(NodeVisitor, Collection) with one root.
        Parameters:
        nodeVisitor - the visitor of the nodes
        root - the root node
        Returns:
        the accumulation result of this traversal
      • preOrder

        public java.lang.Object preOrder​(NodeVisitor nodeVisitor,
                                         java.util.Collection<? extends Node> roots)
        Pre-Order traversal: This is a specialized version of depthFirst with only the enter phase.
        Parameters:
        nodeVisitor - the visitor of the nodes
        roots - the root nodes
        Returns:
        the accumulation result of this traversal
      • postOrder

        public java.lang.Object postOrder​(NodeVisitor nodeVisitor,
                                          Node root)
        Version of postOrder(NodeVisitor, Collection) with one root.
        Parameters:
        nodeVisitor - the visitor of the nodes
        root - the root node
        Returns:
        the accumulation result of this traversal
      • postOrder

        public java.lang.Object postOrder​(NodeVisitor nodeVisitor,
                                          java.util.Collection<? extends Node> roots)
        Post-Order traversal: This is a specialized version of depthFirst with only the leave phase.
        Parameters:
        nodeVisitor - the visitor of the nodes
        roots - the root nodes
        Returns:
        the accumulation result of this traversal
      • oneVisitWithResult

        public static <T> T oneVisitWithResult​(Node node,
                                               NodeVisitor nodeVisitor)