org.geotools.graph.structure.basic
Class BasicGraph

java.lang.Object
  extended byorg.geotools.graph.structure.basic.BasicGraph
All Implemented Interfaces:
Graph, java.io.Serializable
Direct Known Subclasses:
BasicDirectedGraph

public class BasicGraph
extends java.lang.Object
implements Graph, java.io.Serializable

Basic implemenation of Graph.

Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
See Also:
Graph, Serialized Form

Field Summary
 
Fields inherited from interface org.geotools.graph.structure.Graph
FAIL_QUERY, PASS_AND_CONTINUE, PASS_AND_STOP
 
Constructor Summary
BasicGraph()
          Constructs an empty graph with edge and node collections uninitialized.
BasicGraph(java.util.Collection nodes, java.util.Collection edges)
          Constructs a graph from a collection of nodes and a collection of edges.
 
Method Summary
 java.util.Collection getEdges()
          Returns the edges of the graph.
 java.util.Collection getNodes()
          Returns the nodes of the graph.
 java.util.List getNodesOfDegree(int n)
          Returns all the nodes in the graph of a specified degree.
 java.util.List getVisitedEdges(boolean visited)
          Returns all the edges in the graph that have been marked as visited or non-visited.
 java.util.List getVisitedNodes(boolean visited)
          Returns all the nodes in the graph that have been marked as visited or non-visited.
 void initEdges()
          Initializes the edges in the graph by setting all visited flags to false and all visited counts to zero.
 void initNodes()
          Initializes the nodes in the graph by setting all visited flags to false and all visited counts to zero.
 java.util.List queryEdges(GraphVisitor visitor)
          Performs a query against the edges of the graph.
 java.util.List queryNodes(GraphVisitor visitor)
          Performs a query against the nodes of the graph.
 void setEdges(java.util.Collection edges)
          Sets the edge collection for the graph.
 void setNodes(java.util.Collection nodes)
          Sets the node collection of the graph.
 java.lang.String toString()
          Returns the string representation of the graph which is just the string representation of the edge and node collections.
 void visitEdges(GraphVisitor visitor)
          Applies the visitor pattern to the edges of the graph.
 void visitNodes(GraphVisitor visitor)
          Applies the visitor pattern to the nodes of the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicGraph

public BasicGraph()
Constructs an empty graph with edge and node collections uninitialized. Mainly for serializability purposes.


BasicGraph

public BasicGraph(java.util.Collection nodes,
                  java.util.Collection edges)
Constructs a graph from a collection of nodes and a collection of edges. The relationships between the nodes (edges) are already assumed to be formed. Only the references to the node and edge collections are copied, not the underlying collections themselves.

Parameters:
nodes - Collection of nodes to be contained by the graph.
edges - Collection of edges to be contained by the graph.
Method Detail

setNodes

public void setNodes(java.util.Collection nodes)
Sets the node collection of the graph.

Parameters:
nodes - Collection of Node objects.

getNodes

public java.util.Collection getNodes()
Description copied from interface: Graph
Returns the nodes of the graph.

Specified by:
getNodes in interface Graph
Returns:
A collection of Node objects.
See Also:
Graph.getNodes()

setEdges

public void setEdges(java.util.Collection edges)
Sets the edge collection for the graph.

Parameters:
edges - Collection of Edge objects.

getEdges

public java.util.Collection getEdges()
Description copied from interface: Graph
Returns the edges of the graph.

Specified by:
getEdges in interface Graph
Returns:
A collection of Edge objects.
See Also:
Graph.getEdges()

queryNodes

public java.util.List queryNodes(GraphVisitor visitor)
Description copied from interface: Graph
Performs a query against the nodes of the graph. Each Node object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.

Specified by:
queryNodes in interface Graph
Parameters:
visitor - Determines if node meets query criteria. Returns MEET_AND_CONTINUE to signal that the node meets the query criteria and the query should continue.
Returns MEET_AND_STOP to signal that the node meest the query criteria and the query should stop.
FAIL_QUERY to signal that the node does NOT meet the query criteria.
Returns:
A collection of nodes that meet the query criteria.
See Also:
Graph.queryNodes(GraphVisitor)

queryEdges

public java.util.List queryEdges(GraphVisitor visitor)
Description copied from interface: Graph
Performs a query against the edges of the graph. Each Edge object contained in the graph is passed to a GraphVisitor to determine if it meets the query criteria.

Specified by:
queryEdges in interface Graph
Parameters:
visitor - Determines if the meets the query criteria.
Returns MEET_AND_CONTINUE to signal that the edge meets the query criteria and the query should continue.
Returns MEET_AND_STOP to signal that the edge meest the query criteria and the query should stop.
FAIL_QUERY to signal that the edge does NOT meet the query criteria.
Returns:
A collection of edges that meet the query criteria.
See Also:
Graph.queryEdges(GraphVisitor)

visitNodes

public void visitNodes(GraphVisitor visitor)
Description copied from interface: Graph
Applies the visitor pattern to the nodes of the graph.

Specified by:
visitNodes in interface Graph
Parameters:
visitor -
See Also:
Graph.visitNodes(GraphVisitor)

visitEdges

public void visitEdges(GraphVisitor visitor)
Description copied from interface: Graph
Applies the visitor pattern to the edges of the graph.

Specified by:
visitEdges in interface Graph
Parameters:
visitor -
See Also:
Graph.visitEdges(GraphVisitor)

getNodesOfDegree

public java.util.List getNodesOfDegree(int n)
Description copied from interface: Graph
Returns all the nodes in the graph of a specified degree. The degree of a node is the number of edges that are adjacent to the node.

Specified by:
getNodesOfDegree in interface Graph
Parameters:
n - The desired degree of nodes to be returned.
Returns:
A collection of nodes of degree n.
See Also:
Graph.getNodesOfDegree(int), Node.getDegree()

getVisitedNodes

public java.util.List getVisitedNodes(boolean visited)
Description copied from interface: Graph
Returns all the nodes in the graph that have been marked as visited or non-visited.

Specified by:
getVisitedNodes in interface Graph
Parameters:
visited - True if node is visited, false if node is unvisited.
Returns:
List of nodes marked as visited / non-visited.
See Also:
Graph.getVisitedNodes(boolean)

getVisitedEdges

public java.util.List getVisitedEdges(boolean visited)
Description copied from interface: Graph
Returns all the edges in the graph that have been marked as visited or non-visited.

Specified by:
getVisitedEdges in interface Graph
Parameters:
visited - True if edge is visited, false if edge is unvisited.
Returns:
List of edges marked as visited / non-visited.
See Also:
Graph.getVisitedEdges(boolean)

initNodes

public void initNodes()
Initializes the nodes in the graph by setting all visited flags to false and all visited counts to zero.

See Also:
BasicGraphable.isVisited(), BasicGraphable.getCount()

initEdges

public void initEdges()
Initializes the edges in the graph by setting all visited flags to false and all visited counts to zero.

See Also:
BasicGraphable.isVisited(), BasicGraphable.getCount()

toString

public java.lang.String toString()
Returns the string representation of the graph which is just the string representation of the edge and node collections.

Returns:
String represtentaton of graph.


Copyright © GeoTools. All Rights Reserved.