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


001:        package org.geotools.caching.quatree;
002:
003:        import com.vividsolutions.jts.geom.Coordinate;
004:        import com.vividsolutions.jts.geom.Envelope;
005:
006:        import junit.framework.Test;
007:        import junit.framework.TestCase;
008:        import junit.framework.TestSuite;
009:
010:        import org.geotools.caching.Generator;
011:        import org.geotools.caching.spatialindex.spatialindex.Region;
012:
013:        import org.geotools.data.DefaultQuery;
014:        import org.geotools.data.Query;
015:
016:        import org.geotools.feature.FeatureType;
017:
018:        import org.geotools.filter.FilterFactoryImpl;
019:        import org.geotools.filter.spatial.BBOXImpl;
020:
021:        import org.opengis.filter.Filter;
022:
023:        import java.util.ArrayList;
024:        import java.util.Iterator;
025:        import java.util.List;
026:
027:        public class QuadTreeQueryTrackerTest extends TestCase {
028:            private final static short ERROR = -1;
029:            private final static short UNCHANGED = 0;
030:            private final static short OPTIMIZED = 1;
031:            private final static short EMPTYQUERY = 2;
032:            private final static short EXPANDED = 3;
033:            private final List querySet = new ArrayList();
034:            private FeatureType type;
035:            private QuadTreeQueryTracker tracker;
036:
037:            protected void setUp() {
038:                Generator gen = new Generator(1000, 1000);
039:                type = gen.getFeatureType();
040:                tracker = new QuadTreeQueryTracker(new Region(new double[] { 0,
041:                        0 }, new double[] { 1000, 1000 }), type);
042:            }
043:
044:            public static Test suite() {
045:                return new TestSuite(QuadTreeQueryTrackerTest.class);
046:            }
047:
048:            public void testTracker() {
049:                createQuerySet(50);
050:
051:                int unchanged = 0;
052:                int optimized = 0;
053:                int empty = 0;
054:                int expanded = 0;
055:
056:                for (Iterator i = querySet.iterator(); i.hasNext();) {
057:                    Query q = (Query) i.next();
058:                    Query m = tracker.match(q);
059:                    short comp = compareQuery(q, m);
060:
061:                    //String msg = "" ;
062:                    if (comp == UNCHANGED) {
063:                        //msg = "Unchanged" ;
064:                        unchanged++;
065:                        tracker.register(m);
066:                    } else if (comp == OPTIMIZED) {
067:                        //msg = "Optimized" ;
068:                        optimized++;
069:                        tracker.register(m);
070:                    } else if (comp == EMPTYQUERY) {
071:                        //msg = "" ;
072:                        empty++;
073:                    } else if (comp == EXPANDED) {
074:                        expanded++;
075:                        tracker.register(m);
076:                    }
077:                }
078:
079:                System.out.println("Unchanged=" + unchanged + ", Optimized="
080:                        + optimized + ", Empty=" + empty + ", Expanded="
081:                        + expanded);
082:
083:                //assertTrue(unchanged > 0);
084:                //assertTrue(optimized > 0);
085:                //assertTrue(empty > ((2 / 3) * querySet.size()));
086:            }
087:
088:            public void testRegister() {
089:                createQuerySet(1);
090:
091:                Query control = (Query) querySet.get(0);
092:                Query m = tracker.match(control);
093:                short comp = compareQuery(control, m);
094:                assertTrue((comp == UNCHANGED) || (comp == EXPANDED));
095:                tracker.register(m);
096:                m = tracker.match(control);
097:                assertEquals(EMPTYQUERY, compareQuery(control, m));
098:                // test for repetibility
099:                m = tracker.match(control);
100:                assertEquals(EMPTYQUERY, compareQuery(control, m));
101:            }
102:
103:            public void testUnregister() {
104:                /*FilterFactoryImpl ff = new FilterFactoryImpl() ;
105:                    Filter f = ff.bbox(type.getTypeName(), 10, 20, 15, 25, "") ;
106:                    Query q = new DefaultQuery(type.getTypeName(), f) ; */
107:                createQuerySet(1);
108:
109:                Query q = (Query) querySet.get(0);
110:                Query m = tracker.match(q);
111:                short comp = compareQuery(q, m);
112:                assertTrue((comp == UNCHANGED) || (comp == EXPANDED));
113:                tracker.register(m);
114:                m = tracker.match(q);
115:                assertEquals(EMPTYQUERY, compareQuery(q, m));
116:                tracker.unregister(q);
117:                m = tracker.match(q);
118:                comp = compareQuery(q, m);
119:                assertTrue((comp == UNCHANGED) || (comp == EXPANDED));
120:                // test for repetibility
121:                tracker.unregister(q);
122:                m = tracker.match(q);
123:                comp = compareQuery(q, m);
124:                assertTrue((comp == UNCHANGED) || (comp == EXPANDED));
125:            }
126:
127:            //
128:            // Utilities //
129:            //
130:            private void createQuerySet(int numberOfQueries) {
131:                System.out.println("=== Creating Query Set");
132:
133:                Coordinate p = Generator.pickRandomPoint(new Coordinate(500,
134:                        500), 950, 950);
135:                Coordinate last = p;
136:
137:                for (int i = 0; i < numberOfQueries; i++) {
138:                    querySet.add(Generator.createBboxQuery(p, 100, 100));
139:                    p = Generator.pickRandomPoint(p, 50, 50);
140:                    querySet.add(Generator.createBboxQuery(p, 50, 50));
141:                    p = Generator.pickRandomPoint(p, 20, 20);
142:                    querySet.add(Generator.createBboxQuery(p, 20, 20));
143:
144:                    Coordinate temp = p;
145:                    p = last;
146:                    last = temp;
147:                }
148:            }
149:
150:            private short compareQuery(Query q1, Query q2) {
151:                if (q1.equals(q2)) {
152:                    return UNCHANGED;
153:                }
154:
155:                if ((q1.getFilter() instanceof  BBOXImpl)
156:                        && (q2.getFilter() instanceof  BBOXImpl)) {
157:                    BBOXImpl bb = (BBOXImpl) q1.getFilter();
158:                    Envelope env1 = new Envelope(bb.getMinX(), bb.getMaxX(), bb
159:                            .getMinY(), bb.getMaxY());
160:                    bb = (BBOXImpl) q2.getFilter();
161:
162:                    Envelope env2 = new Envelope(bb.getMinX(), bb.getMaxX(), bb
163:                            .getMinY(), bb.getMaxY());
164:
165:                    if (env1.equals(env2)) {
166:                        return UNCHANGED;
167:                    } else if (env1.contains(env2)) {
168:                        return OPTIMIZED;
169:                    } else if (env2.contains(env1)) {
170:                        return EXPANDED;
171:                    } else {
172:                        return ERROR;
173:                    }
174:                } else {
175:                    return EMPTYQUERY;
176:                }
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.