net.ggtools.grand.graph
Class GraphCrawler

java.lang.Object
  extended by net.ggtools.grand.graph.GraphCrawler

public class GraphCrawler
extends java.lang.Object

Walks a graph starting from a specific node to find all the nodes accessible from it.

Author:
Christophe Labouisse

Constructor Summary
GraphCrawler(Graph graph, LinkFinder finder)
          Creates a new crawler.
 
Method Summary
 java.util.Collection crawl(Node startNode)
          Walks the graph from startNode and returns the traversed nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 java.util.Collection 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 findout 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.


Copyright © 2004-2005 ggTools. All Rights Reserved.