Package net.ggtools.grand.graph
Class GraphCrawler
- java.lang.Object
-
- net.ggtools.grand.graph.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 Summary
Constructors Constructor Description GraphCrawler(Graph graph, LinkFinder finder)
Creates a new crawler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<Node>
crawl(Node startNode)
Walks the graph fromstartNode
and returns the traversed nodes.
-
-
-
Constructor Detail
-
GraphCrawler
public GraphCrawler(Graph graph, LinkFinder finder)
Creates a new crawler.- Parameters:
graph
- graph to inspectfinder
- finder to use.
-
-
Method Detail
-
crawl
public final Collection<Node> crawl(Node startNode)
Walks the graph fromstartNode
and returns the traversed nodes. The method maintain a list of nodes to visit initialized withstartNode
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.
-
-