Class GraphCrawler


  • public class GraphCrawler
    extends Object
    Walks a graph starting from a specific node to find all the nodes accessible from it.
    Author:
    Christophe Labouisse
    • Constructor Detail

      • GraphCrawler

        public GraphCrawler​(Graph graph,
                            LinkFinder finder)
        Creates a new crawler.
        Parameters:
        graph - graph to inspect
        finder - finder to use.
    • Method Detail

      • crawl

        public final Collection<Node> crawl​(Node startNode)
        Walks the graph from startNode and returns the traversed nodes. The method maintain a list of nodes to visit initialized with startNode and a LinkedHashSet of results. The startNode is popped from the list, added to the result set, and the finder is used to find all the accessible nodes from it. The nodes founds are added to the list of nodes to visit. This continue until there is no node to visit.
        Parameters:
        startNode - node to start the crawl from.
        Returns:
        a collection containing the traversed nodes.