Source Code Cross Referenced for PlanarGraph.java in  » GIS » jts » com » vividsolutions » jts » planargraph » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » jts » com.vividsolutions.jts.planargraph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The JTS Topology Suite is a collection of Java classes that
003:         * implement the fundamental operations required to validate a given
004:         * geo-spatial data set to a known topological specification.
005:         *
006:         * Copyright (C) 2001 Vivid Solutions
007:         *
008:         * This library is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2.1 of the License, or (at your option) any later version.
012:         *
013:         * This library is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public
019:         * License along with this library; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:         *
022:         * For more information, contact:
023:         *
024:         *     Vivid Solutions
025:         *     Suite #1A
026:         *     2328 Government Street
027:         *     Victoria BC  V8T 5G5
028:         *     Canada
029:         *
030:         *     (250)385-6040
031:         *     www.vividsolutions.com
032:         */
033:        package com.vividsolutions.jts.planargraph;
034:
035:        import java.util.*;
036:        import com.vividsolutions.jts.geom.Coordinate;
037:
038:        /**
039:         * Represents a directed graph which is embeddable in a planar surface.
040:         * <p>
041:         * This class and the other classes in this package serve as a framework for
042:         * building planar graphs for specific algorithms. This class must be
043:         * subclassed to expose appropriate methods to construct the graph. This allows
044:         * controlling the types of graph components ({@link DirectedEdge}s,
045:         * {@link Edge}s and {@link Node}s) which can be added to the graph. An
046:         * application which uses the graph framework will almost always provide
047:         * subclasses for one or more graph components, which hold application-specific
048:         * data and graph algorithms.
049:         *
050:         * @version 1.7
051:         */
052:        public abstract class PlanarGraph {
053:            protected Set edges = new HashSet();
054:            protected Set dirEdges = new HashSet();
055:            protected NodeMap nodeMap = new NodeMap();
056:
057:            /**
058:             * Constructs a empty graph.
059:             */
060:            public PlanarGraph() {
061:            }
062:
063:            /**
064:             * Returns the {@link Node} at the given location,
065:             * or null if no {@link Node} was there.
066:             *
067:             * @param pt the location to query
068:             * @return the node found
069:             * @return <code>null</code> if this graph contains no node at the location
070:             */
071:            public Node findNode(Coordinate pt) {
072:                return (Node) nodeMap.find(pt);
073:            }
074:
075:            /**
076:             * Adds a node to the map, replacing any that is already at that location.
077:             * Only subclasses can add Nodes, to ensure Nodes are of the right type.
078:             * @return the added node
079:             */
080:            protected void add(Node node) {
081:                nodeMap.add(node);
082:            }
083:
084:            /**
085:             * Adds the Edge and its DirectedEdges with this PlanarGraph.
086:             * Assumes that the Edge has already been created with its associated DirectEdges.
087:             * Only subclasses can add Edges, to ensure the edges added are of the right class.
088:             */
089:            protected void add(Edge edge) {
090:                edges.add(edge);
091:                add(edge.getDirEdge(0));
092:                add(edge.getDirEdge(1));
093:            }
094:
095:            /**
096:             * Adds the Edge to this PlanarGraph; only subclasses can add DirectedEdges,
097:             * to ensure the edges added are of the right class.
098:             */
099:            protected void add(DirectedEdge dirEdge) {
100:                dirEdges.add(dirEdge);
101:            }
102:
103:            /**
104:             * Returns an Iterator over the Nodes in this PlanarGraph.
105:             */
106:            public Iterator nodeIterator() {
107:                return nodeMap.iterator();
108:            }
109:
110:            /**
111:             * Returns the Nodes in this PlanarGraph.
112:             */
113:
114:            /**
115:             * Tests whether this graph contains the given {@link Edge}
116:             *
117:             * @param e the edge to query
118:             * @return <code>true</code> if the graph contains the edge
119:             */
120:            public boolean contains(Edge e) {
121:                return edges.contains(e);
122:            }
123:
124:            /**
125:             * Tests whether this graph contains the given {@link DirectedEdge}
126:             *
127:             * @param de the directed edge to query
128:             * @return <code>true</code> if the graph contains the directed edge
129:             */
130:            public boolean contains(DirectedEdge de) {
131:                return dirEdges.contains(de);
132:            }
133:
134:            public Collection getNodes() {
135:                return nodeMap.values();
136:            }
137:
138:            /**
139:             * Returns an Iterator over the DirectedEdges in this PlanarGraph, in the order in which they
140:             * were added.
141:             *
142:             * @see #add(Edge)
143:             * @see #add(DirectedEdge)
144:             */
145:            public Iterator dirEdgeIterator() {
146:                return dirEdges.iterator();
147:            }
148:
149:            /**
150:             * Returns an Iterator over the Edges in this PlanarGraph, in the order in which they
151:             * were added.
152:             *
153:             * @see #add(Edge)
154:             */
155:            public Iterator edgeIterator() {
156:                return edges.iterator();
157:            }
158:
159:            /**
160:             * Returns the Edges that have been added to this PlanarGraph
161:             * @see #add(Edge)
162:             */
163:            public Collection getEdges() {
164:                return edges;
165:            }
166:
167:            /**
168:             * Removes an {@link Edge} and its associated {@link DirectedEdge}s
169:             * from their from-Nodes and from the graph.
170:             * Note: This method does not remove the {@link Node}s associated
171:             * with the {@link Edge}, even if the removal of the {@link Edge}
172:             * reduces the degree of a {@link Node} to zero.
173:             */
174:            public void remove(Edge edge) {
175:                remove(edge.getDirEdge(0));
176:                remove(edge.getDirEdge(1));
177:                edges.remove(edge);
178:                edge.remove();
179:            }
180:
181:            /**
182:             * Removes DirectedEdge from its from-Node and from this PlanarGraph.
183:             * This method does not remove the Nodes associated with the DirectedEdge,
184:             * even if the removal of the DirectedEdge reduces the degree of a Node to
185:             * zero.
186:             */
187:            public void remove(DirectedEdge de) {
188:                DirectedEdge sym = de.getSym();
189:                if (sym != null)
190:                    sym.setSym(null);
191:                de.getFromNode().getOutEdges().remove(de);
192:                de.remove();
193:                dirEdges.remove(de);
194:            }
195:
196:            /**
197:             * Removes a node from the graph, along with any associated DirectedEdges and
198:             * Edges.
199:             */
200:            public void remove(Node node) {
201:                // unhook all directed edges
202:                List outEdges = node.getOutEdges().getEdges();
203:                for (Iterator i = outEdges.iterator(); i.hasNext();) {
204:                    DirectedEdge de = (DirectedEdge) i.next();
205:                    DirectedEdge sym = de.getSym();
206:                    // remove the diredge that points to this node
207:                    if (sym != null)
208:                        remove(sym);
209:                    // remove this diredge from the graph collection
210:                    dirEdges.remove(de);
211:
212:                    Edge edge = de.getEdge();
213:                    if (edge != null) {
214:                        edges.remove(edge);
215:                    }
216:
217:                }
218:                // remove the node from the graph
219:                nodeMap.remove(node.getCoordinate());
220:                node.remove();
221:            }
222:
223:            /**
224:             * Returns all Nodes with the given number of Edges around it.
225:             */
226:            public List findNodesOfDegree(int degree) {
227:                List nodesFound = new ArrayList();
228:                for (Iterator i = nodeIterator(); i.hasNext();) {
229:                    Node node = (Node) i.next();
230:                    if (node.getDegree() == degree)
231:                        nodesFound.add(node);
232:                }
233:                return nodesFound;
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.