Source Code Cross Referenced for BasicGraphGenerator.java in  » GIS » GeoTools-2.4.1 » org » geotools » graph » build » basic » 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 » GeoTools 2.4.1 » org.geotools.graph.build.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005:         *    (C) 2002, Refractions Reserach Inc.
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation;
010:         *    version 2.1 of the License.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.graph.build.basic;
018:
019:        import java.util.HashMap;
020:
021:        import org.geotools.graph.build.GraphBuilder;
022:        import org.geotools.graph.build.GraphGenerator;
023:        import org.geotools.graph.structure.Edge;
024:        import org.geotools.graph.structure.Graph;
025:        import org.geotools.graph.structure.Graphable;
026:        import org.geotools.graph.structure.Node;
027:
028:        /**
029:         * An implementation of GraphGenerator. Graphs are generated as follows:<BR>
030:         * <UL>
031:         * <LI>Objects added to the generator are 2 element object arrays.</LI>
032:         * <LI>The elements of the array represent the objects modelled by the nodes.
033:         * <LI>The object array itself is the object modelled by the edges.
034:         * <LI>As each object array is added to the generator:
035:         *   <UL>
036:         *   <LI>A node lookup table is queried using the elements of the object array.
037:         *   <LI>If a node lookup returns null, a new node is created for its respective
038:         *       object.
039:         *   <LI>A new edge is created incident to the two looked up nodes.
040:         *   <LI>The underlying object of the edge is set to the be object array. 
041:         *   </UL>
042:         * </UL> 
043:         * 
044:         * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
045:         *
046:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/build/basic/BasicGraphGenerator.java $
047:         */
048:        public class BasicGraphGenerator implements  GraphGenerator {
049:
050:            /** The underlying builder **/
051:            private GraphBuilder m_builder;
052:
053:            /** object to node lookup table **/
054:            private HashMap m_obj2graphable;
055:
056:            /** 
057:             * Constructs a new generator.
058:             */
059:            public BasicGraphGenerator() {
060:                m_obj2graphable = new HashMap();
061:                setGraphBuilder(new BasicGraphBuilder());
062:            }
063:
064:            /**
065:             * @see GraphGenerator#add(Object)
066:             */
067:            public Graphable add(Object obj) {
068:                Object[] objs = (Object[]) obj;
069:
070:                Node n1, n2;
071:
072:                //look up first node and create if necessary
073:                if ((n1 = (Node) m_obj2graphable.get(objs[0])) == null) {
074:                    n1 = getGraphBuilder().buildNode();
075:                    n1.setObject(objs[0]);
076:
077:                    getGraphBuilder().addNode(n1);
078:                    m_obj2graphable.put(objs[0], n1);
079:                }
080:
081:                //look up second node and create if necessary
082:                if ((n2 = (Node) m_obj2graphable.get(objs[1])) == null) {
083:                    n2 = getGraphBuilder().buildNode();
084:                    n2.setObject(objs[1]);
085:
086:                    getGraphBuilder().addNode(n2);
087:                    m_obj2graphable.put(objs[1], n2);
088:                }
089:
090:                //create edge and set underlying object
091:                Edge e = getGraphBuilder().buildEdge(n1, n2);
092:                e.setObject(obj);
093:
094:                getGraphBuilder().addEdge(e);
095:
096:                return (e);
097:            }
098:
099:            /**
100:             * @see GraphGenerator#get(Object)
101:             */
102:            public Graphable get(Object obj) {
103:                Object[] objs = (Object[]) obj;
104:                Node n1 = (Node) m_obj2graphable.get(objs[0]);
105:                Node n2 = (Node) m_obj2graphable.get(objs[1]);
106:
107:                return (n1.getEdge(n2));
108:            }
109:
110:            /**
111:             * @see GraphGenerator#remove(Object)
112:             */
113:            public Graphable remove(Object obj) {
114:                Object[] objs = (Object[]) obj;
115:
116:                Node n1 = (Node) m_obj2graphable.get(objs[0]);
117:                Node n2 = (Node) m_obj2graphable.get(objs[1]);
118:
119:                Edge e = n1.getEdge(n2);
120:                getGraphBuilder().removeEdge(e);
121:
122:                return (e);
123:            }
124:
125:            /**
126:             * @see GraphGenerator#setGraphBuilder(GraphBuilder)
127:             */
128:            public void setGraphBuilder(GraphBuilder builder) {
129:                m_builder = builder;
130:            }
131:
132:            /**
133:             * @see GraphGenerator#getGraphBuilder()
134:             */
135:            public GraphBuilder getGraphBuilder() {
136:                return (m_builder);
137:            }
138:
139:            /**
140:             * @see GraphGenerator#getGraph()
141:             */
142:            public Graph getGraph() {
143:                return (m_builder.getGraph());
144:            }
145:
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.