Class CollectNodesVisitor<T extends Visitable>

  • All Implemented Interfaces:
    Visitor

    public class CollectNodesVisitor<T extends Visitable>
    extends java.lang.Object
    implements Visitor
    Collect all nodes of the designated type to be returned in a list.

    Can find any type of node -- the class or class name of the target node is passed in as a constructor parameter.

    • Constructor Summary

      Constructors 
      Constructor Description
      CollectNodesVisitor​(java.lang.Class<T> nodeClass)
      Construct a visitor
      CollectNodesVisitor​(java.lang.Class<T> nodeClass, java.lang.Class<? extends Visitable> skipOverClass)
      Construct a visitor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> getList()
      Return the list of matching nodes.
      boolean skipChildren​(Visitable node)
      Don't visit children under the skipOverClass node, if it isn't null.
      boolean stopTraversal()
      Method that is called to see if query tree traversal should be stopped before visiting all nodes.
      Visitable visit​(Visitable node)
      If we have found the target node, we are done.
      boolean visitChildrenFirst​(Visitable node)
      Method that is called to see if visit() should be called on the children of node before it is called on node itself.
      • Methods inherited from class java.lang.Object

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

      • nodeList

        private final java.util.List<T extends Visitable> nodeList
      • nodeClass

        private final java.lang.Class<T extends Visitable> nodeClass
      • skipOverClass

        private final java.lang.Class<? extends Visitable> skipOverClass
    • Constructor Detail

      • CollectNodesVisitor

        public CollectNodesVisitor​(java.lang.Class<T> nodeClass)
        Construct a visitor
        Parameters:
        nodeClass - the class of the node that we are looking for.
      • CollectNodesVisitor

        public CollectNodesVisitor​(java.lang.Class<T> nodeClass,
                                   java.lang.Class<? extends Visitable> skipOverClass)
        Construct a visitor
        Parameters:
        nodeClass - the class of the node that we are looking for.
        skipOverClass - do not go below this node when searching for nodeClass.
    • Method Detail

      • visitChildrenFirst

        public boolean visitChildrenFirst​(Visitable node)
        Description copied from interface: Visitor
        Method that is called to see if visit() should be called on the children of node before it is called on node itself. If this method always returns true, the visitor will walk the tree bottom-up. If it always returns false, the tree is visited top-down.
        Specified by:
        visitChildrenFirst in interface Visitor
        Parameters:
        node - the top node of a sub-tree about to be visited
        Returns:
        true if node's children should be visited before node, false otherwise
      • stopTraversal

        public boolean stopTraversal()
        Description copied from interface: Visitor
        Method that is called to see if query tree traversal should be stopped before visiting all nodes. Useful for short circuiting traversal if we already know we are done.
        Specified by:
        stopTraversal in interface Visitor
        Returns:
        true/false
      • visit

        public Visitable visit​(Visitable node)
        If we have found the target node, we are done.
        Specified by:
        visit in interface Visitor
        Parameters:
        node - the node to process
        Returns:
        me
      • skipChildren

        public boolean skipChildren​(Visitable node)
        Don't visit children under the skipOverClass node, if it isn't null.
        Specified by:
        skipChildren in interface Visitor
        Parameters:
        node - the node to process
        Returns:
        true/false
      • getList

        public java.util.List<T> getList()
        Return the list of matching nodes. The returned list may be empty, if there are no matching nodes. It is never null.