01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.build.basic;
18:
19: import org.geotools.graph.build.GraphBuilder;
20: import org.geotools.graph.structure.DirectedEdge;
21: import org.geotools.graph.structure.DirectedNode;
22: import org.geotools.graph.structure.Edge;
23: import org.geotools.graph.structure.Graph;
24: import org.geotools.graph.structure.Node;
25: import org.geotools.graph.structure.basic.BasicDirectedEdge;
26: import org.geotools.graph.structure.basic.BasicDirectedGraph;
27: import org.geotools.graph.structure.basic.BasicDirectedNode;
28:
29: /**
30: * An implementation of GraphBuilder used to build directed graphs.
31: *
32: * @see org.geotools.graph.structure.DirectedGraph
33: *
34: * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
35: *
36: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/build/basic/BasicDirectedGraphBuilder.java $
37: */
38: public class BasicDirectedGraphBuilder extends BasicGraphBuilder {
39:
40: /**
41: * Builds a directed node.
42: *
43: * @see DirectedNode
44: * @see GraphBuilder#buildNode()
45: */
46: public Node buildNode() {
47: return (new BasicDirectedNode());
48: }
49:
50: /**
51: * Builds a directed edge.
52: *
53: * @see DirectedEdge
54: * @see GraphBuilder#buildEdge()
55: */
56: public Edge buildEdge(Node nodeA, Node nodeB) {
57: return (new BasicDirectedEdge((DirectedNode) nodeA,
58: (DirectedNode) nodeB));
59: }
60:
61: /**
62: * Adds a directed edge to the graph.
63: *
64: * @see DirectedEdge
65: * @see GraphBuilder#addEdge(Edge)
66: */
67: public void addEdge(Edge edge) {
68: DirectedEdge de = (DirectedEdge) edge;
69: de.getInNode().addOut(de);
70: de.getOutNode().addIn(de);
71: getEdges().add(de);
72: }
73:
74: /**
75: * Creates a directed graph object.
76: */
77: protected Graph buildGraph() {
78: return (new BasicDirectedGraph(getNodes(), getEdges()));
79: }
80:
81: }
|