Class Visits


  • public class Visits
    extends Object
    Utility class that contains visitor/traversal related code
    • Method Detail

      • visit

        public static <S,​R> R visit​(Iterable<? super S> container,
                                          IVisitor<S,​R> visitor)
        Visits container and its children pre-order (parent first). Children are determined by calling Iterable.iterator().
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        container - object whose children will be visited
        visitor - the visitor
        Returns:
        return value from the visitor or null if none
      • visit

        public static <S,​R> R visit​(Iterable<? super S> container,
                                          IVisitor<S,​R> visitor,
                                          IVisitFilter filter)
        Visits container and its children pre-order (parent first). Children are determined by calling Iterable.iterator().
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        container - object whose children will be visited
        visitor - the visitor
        filter - filter used to limit the types of objects that will be visited
        Returns:
        return value from the visitor or null if none
      • visitChildren

        public static <S,​R> R visitChildren​(Iterable<? super S> container,
                                                  IVisitor<S,​R> visitor,
                                                  IVisitFilter filter)
        Visits children of the specified Iterable pre-order (parent first). Children are determined by calling Iterable.iterator().
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        container - object whose children will be visited
        visitor - the visitor
        filter - filter used to limit the types of objects that will be visited
        Returns:
        return value from the visitor or null if none
      • visitChildren

        public static <S,​R> R visitChildren​(Iterable<? super S> container,
                                                  IVisitor<S,​R> visitor)
        Visits children of the specified Iterable pre-order (parent first). Children are determined by calling Iterable.iterator().
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        container - object whose children will be visited
        visitor - the visitor
        Returns:
        return value from the visitor or null if none
      • visitPostOrder

        public static <S,​R> R visitPostOrder​(S root,
                                                   IVisitor<S,​R> visitor)
        Visits the specified object and any of its children using a post-order (child first) traversal. Children are determined by calling Iterable.iterator() if the object implements Iterable.
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        root - root object that will be visited
        visitor - the visitor
        Returns:
        return value from the visitor or null if none
      • visitPostOrder

        public static <S,​R> R visitPostOrder​(Object root,
                                                   IVisitor<S,​R> visitor,
                                                   IVisitFilter filter)
        Visits the specified object and any of its children using a post-order (child first) traversal. Children are determined by calling Iterable.iterator() if the object implements Iterable.
        Type Parameters:
        S - the type of object that will be visited, notice that container is not declared as Iterable<S> because it may return a generalization of S
        R - the type of object that should be returned from the visitor, use Void if no return value is needed
        Parameters:
        root - root object that will be visited
        visitor - the visitor
        filter - filter used to limit the types of objects that will be visited
        Returns:
        return value from the visitor or null if none