org.geotools.graph.build.basic
Class BasicGraphBuilder

java.lang.Object
  extended byorg.geotools.graph.build.basic.BasicGraphBuilder
All Implemented Interfaces:
GraphBuilder
Direct Known Subclasses:
BasicDirectedGraphBuilder, BasicLineGraphBuilder, OptGraphBuilder

public class BasicGraphBuilder
extends java.lang.Object
implements GraphBuilder

Basic implementation of GraphBuilder. This implementation of builder creates the graph when the builder is created. The underlying graph implementation makes copies of the references to the node and edge collections, not copies of the underlying collections themselves. In this way as nodes and edges are added to the builder, it is reflected in the built graph.

Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net

Constructor Summary
BasicGraphBuilder()
          Constructs a new empty graph builder.
 
Method Summary
 void addEdge(Edge edge)
          Checks for loops in which case it only added the edge to the adjacency list of one of the nodes (both of its nodes are the same node).
 void addNode(Node node)
          Adds a node to the graph.
 Edge buildEdge(Node nodeA, Node nodeB)
          Builds a new edge for the graph.
protected  Graph buildGraph()
          Creates the underlying graph object.
 Node buildNode()
          Builds a new node for the graph.
 java.lang.Object clone(boolean deep)
          Returns a clone of the builder.
 java.util.Collection getEdges()
          Returns the edges belonging to the graph being built.
 Graph getGraph()
          Returns the graph being built.
 java.util.Collection getNodes()
          Returns the nodes belonging to the graph being built.
 void importGraph(Graph g)
          Constructs a graph builder from a pre built graph.
 void removeEdge(Edge edge)
          Removes an edge from the graph.
 void removeEdges(java.util.Collection edges)
          Removes a collection of edges from the graph.
 void removeNode(Node node)
          Removes an node from the graph.
 void removeNodes(java.util.Collection nodes)
          Removes a collection of nodes from the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicGraphBuilder

public BasicGraphBuilder()
Constructs a new empty graph builder.

Method Detail

buildNode

public Node buildNode()
Description copied from interface: GraphBuilder
Builds a new node for the graph. This method does not add the new node to the graph, this must be done with the addNode(Node) method.

Specified by:
buildNode in interface GraphBuilder
Returns:
Node The newly built node.
See Also:
GraphBuilder.buildNode()

buildEdge

public Edge buildEdge(Node nodeA,
                      Node nodeB)
Description copied from interface: GraphBuilder
Builds a new edge for the graph. This method does not add the new node to the graph, this must be done with the addEdge(Edge) method.

Specified by:
buildEdge in interface GraphBuilder
Parameters:
nodeA - Adjacent node to edge.
nodeB - Adjacent node to edge.
Returns:
Edge the newly built Edge.
See Also:
GraphBuilder.buildEdge(Node, Node)

addNode

public void addNode(Node node)
Description copied from interface: GraphBuilder
Adds a node to the graph.

Specified by:
addNode in interface GraphBuilder
Parameters:
node - Node to be added to graph.
See Also:
GraphBuilder.addNode(Node)

addEdge

public void addEdge(Edge edge)
Checks for loops in which case it only added the edge to the adjacency list of one of the nodes (both of its nodes are the same node).

Specified by:
addEdge in interface GraphBuilder
Parameters:
edge - Edge to be added to graph.
See Also:
GraphBuilder.addEdge(Edge)

removeNode

public void removeNode(Node node)
Description copied from interface: GraphBuilder
Removes an node from the graph.

Specified by:
removeNode in interface GraphBuilder
Parameters:
node - Node to be removed from graph.
See Also:
GraphBuilder.removeNode(Node)

removeNodes

public void removeNodes(java.util.Collection nodes)
Description copied from interface: GraphBuilder
Removes a collection of nodes from the graph.

Specified by:
removeNodes in interface GraphBuilder
Parameters:
nodes - A collection of nodes to be removed from the graph.
See Also:
GraphBuilder.removeNodes(Collection)

removeEdge

public void removeEdge(Edge edge)
Description copied from interface: GraphBuilder
Removes an edge from the graph.

Specified by:
removeEdge in interface GraphBuilder
Parameters:
edge - Edge to be removed from graph.
See Also:
GraphBuilder.removeEdge(Edge)

removeEdges

public void removeEdges(java.util.Collection edges)
Description copied from interface: GraphBuilder
Removes a collection of edges from the graph.

Specified by:
removeEdges in interface GraphBuilder
Parameters:
edges - Collection of edges to be removed from the graph.
See Also:
GraphBuilder.removeEdges(Collection)

getGraph

public Graph getGraph()
Description copied from interface: GraphBuilder
Returns the graph being built.

Specified by:
getGraph in interface GraphBuilder
Returns:
Graph The graph being built.
See Also:
GraphBuilder.getGraph()

clone

public java.lang.Object clone(boolean deep)
                       throws java.lang.Exception
Description copied from interface: GraphBuilder
Returns a clone of the builder. A deep clone copies the underlying graph structure, a non deep clone results in an empty builder

Specified by:
clone in interface GraphBuilder
Parameters:
deep - Deep or non deep clone.
Returns:
A graph builder.
Throws:
java.lang.Exception
See Also:
GraphBuilder.clone(boolean)

importGraph

public void importGraph(Graph g)
Description copied from interface: GraphBuilder
Constructs a graph builder from a pre built graph. The nodes and edges of the existing graph are imported into the builder. Relationships between nodes and edges are assummed to be preexistant.

Specified by:
importGraph in interface GraphBuilder
See Also:
GraphBuilder.importGraph(Graph)

getNodes

public java.util.Collection getNodes()
Returns the nodes belonging to the graph being built.

Returns:
A collection of nodes.

getEdges

public java.util.Collection getEdges()
Returns the edges belonging to the graph being built.

Returns:
A collection of edges.

buildGraph

protected Graph buildGraph()
Creates the underlying graph object.

Returns:
A Graph object.


Copyright © GeoTools. All Rights Reserved.