Source Code Cross Referenced for BasicDirectedEdge.java in  » GIS » GeoTools-2.4.1 » org » geotools » graph » structure » 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.structure.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.structure.basic;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashSet;
021:        import java.util.Iterator;
022:
023:        import org.geotools.graph.structure.DirectedEdge;
024:        import org.geotools.graph.structure.DirectedNode;
025:        import org.geotools.graph.structure.Edge;
026:        import org.geotools.graph.structure.Node;
027:
028:        /**
029:         * Basic implementation of DirectedEdge.
030:         * 
031:         * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
032:         *
033:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/structure/basic/BasicDirectedEdge.java $
034:         */
035:        public class BasicDirectedEdge extends BasicGraphable implements 
036:                DirectedEdge {
037:
038:            /** in node **/
039:            private DirectedNode m_in;
040:
041:            /** out node **/
042:            private DirectedNode m_out;
043:
044:            /** Contstructs a new DirectedEdge.
045:             * 
046:             * @param in The in node of the edge.
047:             * @param out The out node of the edge.
048:             */
049:            public BasicDirectedEdge(DirectedNode in, DirectedNode out) {
050:                super ();
051:                m_in = in;
052:                m_out = out;
053:            }
054:
055:            /**
056:             * @see DirectedEdge#getInNode()
057:             */
058:            public DirectedNode getInNode() {
059:                return (m_in);
060:            }
061:
062:            /**
063:             * @see DirectedEdge#getOutNode()
064:             */
065:            public DirectedNode getOutNode() {
066:                return (m_out);
067:            }
068:
069:            /**
070:             * Returns the in node.
071:             * 
072:             * @see Edge#getNodeA()
073:             */
074:            public Node getNodeA() {
075:                return (m_in);
076:            }
077:
078:            /**
079:             * Returns the out node.
080:             * 
081:             * @see Edge#getNodeB()
082:             */
083:            public Node getNodeB() {
084:                return (m_out);
085:            }
086:
087:            /**
088:             * @see Edge#getOtherNode(Node)
089:             */
090:            public Node getOtherNode(Node node) {
091:                return (m_in.equals(node) ? m_out : m_out.equals(node) ? m_in
092:                        : null);
093:            }
094:
095:            /**
096:             * Removes the edge from the out list of the in node and from the in list of
097:             * the out node. Nodes are switched and then the edge is added to the in list
098:             * of the new out node, and to the out list of the new in node.
099:             * 
100:             * @see Edge#reverse()
101:             * 
102:             */
103:            public void reverse() {
104:                //remove edge from adjacent nodes
105:                m_in.removeOut(this );
106:                m_out.removeIn(this );
107:
108:                //swap nodes
109:                DirectedNode tmp = m_in;
110:                m_in = m_out;
111:                m_out = tmp;
112:
113:                //re add nodes
114:                m_in.addOut(this );
115:                m_out.addIn(this );
116:            }
117:
118:            /**
119:             * Returns an iterator over all edges incident to both the in and out nodes.
120:             * 
121:             * @see org.geotools.graph.structure.Graphable#getRelated()
122:             */
123:            public Iterator getRelated() {
124:                HashSet related = new HashSet();
125:
126:                //add all edges incident to both nodes
127:                related.addAll(m_in.getEdges());
128:                related.addAll(m_out.getEdges());
129:
130:                //remove this edge
131:                related.remove(this );
132:
133:                return (related.iterator());
134:
135:                //    
136:                //    ArrayList related = new ArrayList();
137:                //    
138:                //    related.addAll(m_in.getInEdges());
139:                //    
140:                //    //add out edges, look for an opposite edge, it will have already 
141:                //    // been added so dont add it
142:                //    for (Iterator itr = m_out.getOutEdges().iterator(); itr.hasNext();) {
143:                //      DirectedEdge de = (DirectedEdge)itr.next();
144:                //      switch(de.compareNodes(this)) {
145:                //        case OPPOSITE_NODE_ORIENTATION: continue;
146:                //      }
147:                //      related.add(de);	
148:                //    }
149:                //    
150:                //    //look for duplicate edges (same direction) if not equal add
151:                //    // dont add opposite edges
152:                //    // dont add loops
153:                //    for (Iterator itr = m_in.getOutEdges().iterator(); itr.hasNext();) {
154:                //      DirectedEdge de = (DirectedEdge)itr.next();
155:                //      switch(de.compareNodes(this)) {
156:                //      	case EQUAL_NODE_ORIENTATION:
157:                //      	  if (!de.equals(this)) 
158:                //      	    related.add(de);
159:                //      	  continue;
160:                //        case OPPOSITE_NODE_ORIENTATION: 
161:                //          continue;
162:                //        case UNEQUAL_NODE_ORIENTATION: 
163:                //          if (de.getNodeA().equals(de.getNodeB())) continue;
164:                //          related.add(de);
165:                //      }
166:                //    }
167:                //    
168:                //    return(related.iterator());
169:            }
170:
171:            /**
172:             * Returns an iterator over the in edges of the in node.
173:             * 
174:             * @see org.geotools.graph.structure.DirectedGraphable#getInRelated()
175:             */
176:            public Iterator getInRelated() {
177:                ArrayList in = new ArrayList();
178:                for (Iterator itr = m_in.getInEdges().iterator(); itr.hasNext();) {
179:                    DirectedEdge de = (DirectedEdge) itr.next();
180:                    //this check has to be because the edge could be a loop in which case
181:                    // it is in related to itself
182:                    if (!de.equals(this ))
183:                        in.add(de);
184:                }
185:                return (in.iterator());
186:            }
187:
188:            /**
189:             * Returns an iterator over the out edges of the out node.
190:             * 
191:             * @see org.geotools.graph.structure.DirectedGraphable#getOutRelated() 
192:             */
193:            public Iterator getOutRelated() {
194:                ArrayList out = new ArrayList();
195:                for (Iterator itr = m_out.getOutEdges().iterator(); itr
196:                        .hasNext();) {
197:                    DirectedEdge de = (DirectedEdge) itr.next();
198:                    //this check has to be because the edge could be a loop in which case
199:                    // it is in related to itself
200:                    if (!de.equals(this ))
201:                        out.add(de);
202:                }
203:                return (out.iterator());
204:            }
205:
206:            /**
207:             * @see Edge#compareNodes(Edge)
208:             */
209:            public int compareNodes(Edge other) {
210:                if (other instanceof  DirectedEdge) {
211:                    DirectedEdge de = (DirectedEdge) other;
212:                    if (de.getInNode().equals(m_in)
213:                            && de.getOutNode().equals(m_out))
214:                        return (EQUAL_NODE_ORIENTATION);
215:                    if (de.getInNode().equals(m_out)
216:                            && de.getOutNode().equals(m_in))
217:                        return (OPPOSITE_NODE_ORIENTATION);
218:                }
219:                return (UNEQUAL_NODE_ORIENTATION);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.