Class Visits


  • public class Visits
    extends java.lang.Object
    Utility class that contains visitor/traversal related code
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <S,​R>
      R
      visit​(java.lang.Iterable<? super S> container, IVisitor<S,​R> visitor)
      Visits container and its children pre-order (parent first).
      static <S,​R>
      R
      visit​(java.lang.Iterable<? super S> container, IVisitor<S,​R> visitor, IVisitFilter filter)
      Visits container and its children pre-order (parent first).
      static <S,​R>
      R
      visitChildren​(java.lang.Iterable<? super S> container, IVisitor<S,​R> visitor)
      Visits children of the specified Iterable pre-order (parent first).
      static <S,​R>
      R
      visitChildren​(java.lang.Iterable<? super S> container, IVisitor<S,​R> visitor, IVisitFilter filter)
      Visits children of the specified Iterable pre-order (parent first).
      static <S,​R>
      R
      visitPostOrder​(java.lang.Object root, IVisitor<S,​R> visitor, IVisitFilter filter)
      Visits the specified object and any of its children using a post-order (child first) traversal.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • visit

        public static <S,​R> R visit​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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