Class Traverser


  • public class Traverser
    extends Object
    • Method Detail

      • preOrderTraversal

        @NotNull
        public static <T> @NotNull org.apache.commons.collections4.FluentIterable<T> preOrderTraversal​(T root,
                                                                                                       @NotNull
                                                                                                       @NotNull Function<T,​Iterable<? extends T>> childExtractor)
        Returns an iterator that traverses a tree structure in pre-order. Null nodes are strictly forbidden.

        In pre-order traversal, the current node is visited first, followed by its children from left to right. This method creates an iterator that produces tree nodes in this order.

        Type Parameters:
        T - the type of value in the tree nodes
        Parameters:
        root - the root node of the tree, may be null
        childExtractor - function to extract children from a node, must not be null
        Returns:
        an iterator that traverses the tree in pre-order
        Throws:
        NullPointerException - if childExtractor or any child is null
      • breadthFirstTraversal

        @NotNull
        public static <T> @NotNull org.apache.commons.collections4.FluentIterable<T> breadthFirstTraversal​(T root,
                                                                                                           @NotNull
                                                                                                           @NotNull Function<T,​Iterable<? extends T>> childExtractor)
        Returns an iterator that traverses a tree structure in breadth-first order. Null nodes are strictly forbidden.

        In breadth-first traversal, all sibling nodes at a given level are visited before any nodes at the next level. This creates a level-by-level traversal pattern, starting from the root and moving downward through the tree.

        Type Parameters:
        T - the type of value in the tree nodes
        Parameters:
        root - the root node of the tree, may be null
        childExtractor - function to extract children from a node, must not be null
        Returns:
        a fluent iterable that traverses the tree in breadth-first order
        Throws:
        NullPointerException - if childExtractor or any child is null
      • postOrderTraversal

        public static <T> org.apache.commons.collections4.FluentIterable<T> postOrderTraversal​(T root,
                                                                                               Function<T,​Iterable<? extends T>> childExtractor)
        Returns an iterator that traverses a tree structure in post-order. Null nodes are strictly forbidden.

        In post-order traversal, all children of a node are visited from left to right, followed by the node itself. This creates a bottom-up traversal pattern where leaf nodes are visited first, then their parents, and finally the root.

        Type Parameters:
        T - the type of value in the tree nodes
        Parameters:
        root - the root node of the tree, may be null
        childExtractor - function to extract children from a node, must not be null
        Returns:
        an iterator that traverses the tree in post-order
        Throws:
        NullPointerException - if childExtractor or any child is null