Source Code Cross Referenced for BreadthFirstTopologicalIterator.java in  » GIS » GeoTools-2.4.1 » org » geotools » graph » traverse » standard » 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.traverse.standard 
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.traverse.standard;
018:
019:        import java.util.Iterator;
020:
021:        import org.geotools.graph.structure.Graph;
022:        import org.geotools.graph.structure.GraphVisitor;
023:        import org.geotools.graph.structure.Graphable;
024:        import org.geotools.graph.structure.Node;
025:        import org.geotools.graph.traverse.GraphTraversal;
026:        import org.geotools.graph.traverse.basic.AbstractGraphIterator;
027:        import org.geotools.graph.util.FIFOQueue;
028:        import org.geotools.graph.util.Queue;
029:
030:        /**
031:         * Iterates over the nodes of a graph in <B>Breadth First Topological Sort</B> 
032:         * pattern. The following is an illustration of the iteration.<BR>
033:         * <IMG src="doc-files/breadth_topo.gif"><BR>
034:         * <BR>
035:         * Initially all nodes of degree less than two are <B>active</B> 
036:         * (ready to be visited). As nodes are visited, a node can become active 
037:         * when all but one of its related nodes have been visited (
038:         * degree = counter + 1). When a node becomes active it is placed into the
039:         * <B>active node queue</B> (queue of nodes to be visited). 
040:         * The Breadth First Topological iterator places
041:         * nodes into the queue in <B>First In First Out</B> order.<BR>
042:         * <BR>
043:         * To determine when a node is to become active the iterator uses the counter
044:         * associated with each node. If these counters are modified by an entity 
045:         * other then the iterator, the iteration may be affected in undefined ways. 
046:         *  
047:         * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
048:         *
049:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/traverse/standard/BreadthFirstTopologicalIterator.java $
050:         */
051:        public class BreadthFirstTopologicalIterator extends
052:                AbstractGraphIterator {
053:
054:            /** Queue of active nodes **/
055:            private Queue m_queue;
056:
057:            /**
058:             * Creates the active queue, and populates it with all nodes of degree less
059:             * than 2. Counters of all nodes are also reset to 0.
060:             * 
061:             * @see org.geotools.graph.traverse.GraphIterator#init(Graph)
062:             */
063:            public void init(Graph graph, GraphTraversal traversal) {
064:                //create queue
065:                m_queue = buildQueue(graph);
066:
067:                //initialize nodes
068:                graph.visitNodes(new GraphVisitor() {
069:                    public int visit(Graphable component) {
070:                        Node node = (Node) component;
071:
072:                        //reset counter to zero
073:                        node.setCount(0);
074:
075:                        if (node.getDegree() < 2)
076:                            m_queue.enq(node);
077:
078:                        return (0);
079:                    }
080:                });
081:            }
082:
083:            /**
084:             * Returns the next node in the active node queue.
085:             * 
086:             * @see org.geotools.graph.traverse.GraphIterator#next()
087:             */
088:            public Graphable next(GraphTraversal traversal) {
089:                return (!m_queue.isEmpty() ? (Graphable) m_queue.deq() : null);
090:            }
091:
092:            /**
093:             * Continues the iteration by incrementing the counters of any unvisited 
094:             * nodes related to the current node. If any related nodes have counters 
095:             * equal to degree of that node - 1, it is placed into the active queue.
096:             * 
097:             * @see org.geotools.graph.traverse.GraphIterator#cont(Graphable)
098:             */
099:            public void cont(Graphable current, GraphTraversal traversal) {
100:                //increment the count of all adjacent nodes by one
101:                // if the result count is 1 less than the degree, place it into the queue
102:                for (Iterator itr = current.getRelated(); itr.hasNext();) {
103:                    Node related = (Node) itr.next();
104:                    if (!traversal.isVisited(related)) {
105:                        related.setCount(related.getCount() + 1);
106:                        if (related.getDegree() - 1 == related.getCount())
107:                            m_queue.enq(related);
108:                    }
109:                }
110:            }
111:
112:            /**
113:             * Kills the current branch of the traversal by not incremening the counters
114:             * of any related nodes.
115:             * 
116:             * @see org.geotools.graph.traverse.GraphIterator#killBranch(Graphable) 
117:             */
118:            public void killBranch(Graphable current, GraphTraversal traversal) {
119:                //do nothing
120:            }
121:
122:            /**
123:             * Builds the active node queue. 
124:             * 
125:             * @param graph The Graph whose components are being iterated over.
126:             * 
127:             * @return A first in first out queue
128:             */
129:            protected Queue buildQueue(Graph graph) {
130:                return (new FIFOQueue(graph.getNodes().size()));
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.