Source Code Cross Referenced for OrderIteratorTest.java in  » RSS-RDF » sesame » org » openrdf » query » algebra » evaluation » iterator » 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 » RSS RDF » sesame » org.openrdf.query.algebra.evaluation.iterator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.query.algebra.evaluation.iterator;
007:
008:        import info.aduna.iteration.CloseableIteratorIteration;
009:
010:        import java.util.ArrayList;
011:        import java.util.Arrays;
012:        import java.util.Collections;
013:        import java.util.Comparator;
014:        import java.util.Iterator;
015:        import java.util.List;
016:        import java.util.Set;
017:
018:        import junit.framework.TestCase;
019:
020:        import org.openrdf.model.Value;
021:        import org.openrdf.query.Binding;
022:        import org.openrdf.query.BindingSet;
023:        import org.openrdf.query.QueryEvaluationException;
024:
025:        /**
026:         * 
027:         * @author james
028:         * 
029:         */
030:        public class OrderIteratorTest extends TestCase {
031:            class IterationStub
032:                    extends
033:                    CloseableIteratorIteration<BindingSet, QueryEvaluationException> {
034:                int hasNextCount = 0;
035:
036:                int nextCount = 0;
037:
038:                int removeCount = 0;
039:
040:                @Override
041:                public void setIterator(Iterator<? extends BindingSet> iter) {
042:                    super .setIterator(iter);
043:                }
044:
045:                @Override
046:                public boolean hasNext() {
047:                    hasNextCount++;
048:                    return super .hasNext();
049:                }
050:
051:                @Override
052:                public BindingSet next() {
053:                    nextCount++;
054:                    return super .next();
055:                }
056:
057:                @Override
058:                public void remove() {
059:                    removeCount++;
060:                }
061:            }
062:
063:            class SizeComparator implements  Comparator<BindingSet> {
064:                public int compare(BindingSet o1, BindingSet o2) {
065:                    return Integer.valueOf(o1.size()).compareTo(
066:                            Integer.valueOf(o2.size()));
067:                }
068:            }
069:
070:            class BindingSetSize implements  BindingSet {
071:                private int size;
072:
073:                public BindingSetSize(int size) {
074:                    super ();
075:                    this .size = size;
076:                }
077:
078:                public Binding getBinding(String bindingName) {
079:                    throw new UnsupportedOperationException();
080:                }
081:
082:                public Set<String> getBindingNames() {
083:                    throw new UnsupportedOperationException();
084:                }
085:
086:                public Value getValue(String bindingName) {
087:                    throw new UnsupportedOperationException();
088:                }
089:
090:                public boolean hasBinding(String bindingName) {
091:                    throw new UnsupportedOperationException();
092:                }
093:
094:                public Iterator<Binding> iterator() {
095:                    throw new UnsupportedOperationException();
096:                }
097:
098:                public int size() {
099:                    return size;
100:                }
101:
102:                @Override
103:                public String toString() {
104:                    return getClass().getSimpleName() + "#" + size;
105:                }
106:            }
107:
108:            private IterationStub iteration;
109:
110:            private OrderIterator order;
111:
112:            private List<BindingSet> list;
113:
114:            private BindingSet b1 = new BindingSetSize(1);
115:
116:            private BindingSet b2 = new BindingSetSize(2);
117:
118:            private BindingSet b3 = new BindingSetSize(3);
119:
120:            private BindingSet b4 = new BindingSetSize(4);
121:
122:            private BindingSet b5 = new BindingSetSize(5);
123:
124:            private SizeComparator cmp;
125:
126:            public void testFirstHasNext() throws Exception {
127:                order.hasNext();
128:                assertEquals(list.size() + 1, iteration.hasNextCount);
129:                assertEquals(list.size(), iteration.nextCount);
130:                assertEquals(0, iteration.removeCount);
131:            }
132:
133:            public void testHasNext() throws Exception {
134:                order.hasNext();
135:                order.next();
136:                order.hasNext();
137:                assertEquals(list.size() + 1, iteration.hasNextCount);
138:                assertEquals(list.size(), iteration.nextCount);
139:                assertEquals(0, iteration.removeCount);
140:            }
141:
142:            public void testFirstNext() throws Exception {
143:                order.next();
144:                assertEquals(list.size() + 1, iteration.hasNextCount);
145:                assertEquals(list.size(), iteration.nextCount);
146:                assertEquals(0, iteration.removeCount);
147:            }
148:
149:            public void testNext() throws Exception {
150:                order.next();
151:                order.next();
152:                assertEquals(list.size() + 1, iteration.hasNextCount);
153:                assertEquals(list.size(), iteration.nextCount);
154:                assertEquals(0, iteration.removeCount);
155:            }
156:
157:            public void testRemove() throws Exception {
158:                try {
159:                    order.remove();
160:                    fail();
161:                } catch (UnsupportedOperationException e) {
162:                }
163:
164:            }
165:
166:            public void testSorting() throws Exception {
167:                List<BindingSet> sorted = new ArrayList<BindingSet>(list);
168:                Collections.sort(sorted, cmp);
169:                for (BindingSet b : sorted) {
170:                    assertEquals(b, order.next());
171:                }
172:                assertFalse(order.hasNext());
173:            }
174:
175:            @Override
176:            protected void setUp() throws Exception {
177:                list = Arrays.asList(b3, b5, b2, b1, b4, b2);
178:                cmp = new SizeComparator();
179:                iteration = new IterationStub();
180:                iteration.setIterator(list.iterator());
181:                order = new OrderIterator(iteration, cmp);
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.