Source Code Cross Referenced for AbstractTestOrderedMap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » map » 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 » Library » Apache common Collections » org.apache.commons.collections.map 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2004 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections.map;
017:
018:        import java.util.ArrayList;
019:        import java.util.Arrays;
020:        import java.util.Collections;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.NoSuchElementException;
025:        import java.util.TreeMap;
026:
027:        import org.apache.commons.collections.BulkTest;
028:        import org.apache.commons.collections.MapIterator;
029:        import org.apache.commons.collections.OrderedMap;
030:        import org.apache.commons.collections.comparators.NullComparator;
031:        import org.apache.commons.collections.iterators.AbstractTestOrderedMapIterator;
032:
033:        /**
034:         * Abstract test class for {@link OrderedMap} methods and contracts.
035:         *
036:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
037:         * 
038:         * @author Stephen Colebourne
039:         */
040:        public abstract class AbstractTestOrderedMap extends
041:                AbstractTestIterableMap {
042:
043:            /**
044:             * JUnit constructor.
045:             * 
046:             * @param testName  the test name
047:             */
048:            public AbstractTestOrderedMap(String testName) {
049:                super (testName);
050:            }
051:
052:            //-----------------------------------------------------------------------
053:            /**
054:             * OrderedMap uses TreeMap as its known comparison.
055:             * 
056:             * @return a map that is known to be valid
057:             */
058:            public Map makeConfirmedMap() {
059:                return new TreeMap(new NullComparator());
060:            }
061:
062:            /**
063:             * The only confirmed collection we have that is ordered is the sorted one.
064:             * Thus, sort the keys.
065:             */
066:            public Object[] getSampleKeys() {
067:                List list = new ArrayList(Arrays.asList(super .getSampleKeys()));
068:                Collections.sort(list, new NullComparator());
069:                return list.toArray();
070:            }
071:
072:            //-----------------------------------------------------------------------
073:            public void testFirstKey() {
074:                resetEmpty();
075:                OrderedMap ordered = (OrderedMap) map;
076:                try {
077:                    ordered.firstKey();
078:                    fail();
079:                } catch (NoSuchElementException ex) {
080:                }
081:
082:                resetFull();
083:                ordered = (OrderedMap) map;
084:                Object confirmedFirst = confirmed.keySet().iterator().next();
085:                assertEquals(confirmedFirst, ordered.firstKey());
086:            }
087:
088:            public void testLastKey() {
089:                resetEmpty();
090:                OrderedMap ordered = (OrderedMap) map;
091:                try {
092:                    ordered.lastKey();
093:                    fail();
094:                } catch (NoSuchElementException ex) {
095:                }
096:
097:                resetFull();
098:                ordered = (OrderedMap) map;
099:                Object confirmedLast = null;
100:                for (Iterator it = confirmed.keySet().iterator(); it.hasNext();) {
101:                    confirmedLast = it.next();
102:                }
103:                assertEquals(confirmedLast, ordered.lastKey());
104:            }
105:
106:            //-----------------------------------------------------------------------    
107:            public void testNextKey() {
108:                resetEmpty();
109:                OrderedMap ordered = (OrderedMap) map;
110:                assertEquals(null, ordered.nextKey(getOtherKeys()[0]));
111:                if (isAllowNullKey() == false) {
112:                    try {
113:                        assertEquals(null, ordered.nextKey(null)); // this is allowed too
114:                    } catch (NullPointerException ex) {
115:                    }
116:                } else {
117:                    assertEquals(null, ordered.nextKey(null));
118:                }
119:
120:                resetFull();
121:                ordered = (OrderedMap) map;
122:                Iterator it = confirmed.keySet().iterator();
123:                Object confirmedLast = it.next();
124:                while (it.hasNext()) {
125:                    Object confirmedObject = it.next();
126:                    assertEquals(confirmedObject, ordered
127:                            .nextKey(confirmedLast));
128:                    confirmedLast = confirmedObject;
129:                }
130:                assertEquals(null, ordered.nextKey(confirmedLast));
131:
132:                if (isAllowNullKey() == false) {
133:                    try {
134:                        ordered.nextKey(null);
135:                        fail();
136:                    } catch (NullPointerException ex) {
137:                    }
138:                } else {
139:                    assertEquals(null, ordered.nextKey(null));
140:                }
141:            }
142:
143:            public void testPreviousKey() {
144:                resetEmpty();
145:                OrderedMap ordered = (OrderedMap) map;
146:                assertEquals(null, ordered.previousKey(getOtherKeys()[0]));
147:                if (isAllowNullKey() == false) {
148:                    try {
149:                        assertEquals(null, ordered.previousKey(null)); // this is allowed too
150:                    } catch (NullPointerException ex) {
151:                    }
152:                } else {
153:                    assertEquals(null, ordered.previousKey(null));
154:                }
155:
156:                resetFull();
157:                ordered = (OrderedMap) map;
158:                List list = new ArrayList(confirmed.keySet());
159:                Collections.reverse(list);
160:                Iterator it = list.iterator();
161:                Object confirmedLast = it.next();
162:                while (it.hasNext()) {
163:                    Object confirmedObject = it.next();
164:                    assertEquals(confirmedObject, ordered
165:                            .previousKey(confirmedLast));
166:                    confirmedLast = confirmedObject;
167:                }
168:                assertEquals(null, ordered.previousKey(confirmedLast));
169:
170:                if (isAllowNullKey() == false) {
171:                    try {
172:                        ordered.previousKey(null);
173:                        fail();
174:                    } catch (NullPointerException ex) {
175:                    }
176:                } else {
177:                    if (isAllowNullKey() == false) {
178:                        assertEquals(null, ordered.previousKey(null));
179:                    }
180:                }
181:            }
182:
183:            //-----------------------------------------------------------------------
184:            public BulkTest bulkTestOrderedMapIterator() {
185:                return new InnerTestOrderedMapIterator();
186:            }
187:
188:            public class InnerTestOrderedMapIterator extends
189:                    AbstractTestOrderedMapIterator {
190:                public InnerTestOrderedMapIterator() {
191:                    super ("InnerTestOrderedMapIterator");
192:                }
193:
194:                public boolean supportsRemove() {
195:                    return AbstractTestOrderedMap.this .isRemoveSupported();
196:                }
197:
198:                public boolean isGetStructuralModify() {
199:                    return AbstractTestOrderedMap.this .isGetStructuralModify();
200:                }
201:
202:                public boolean supportsSetValue() {
203:                    return AbstractTestOrderedMap.this .isSetValueSupported();
204:                }
205:
206:                public MapIterator makeEmptyMapIterator() {
207:                    resetEmpty();
208:                    return ((OrderedMap) AbstractTestOrderedMap.this .map)
209:                            .orderedMapIterator();
210:                }
211:
212:                public MapIterator makeFullMapIterator() {
213:                    resetFull();
214:                    return ((OrderedMap) AbstractTestOrderedMap.this .map)
215:                            .orderedMapIterator();
216:                }
217:
218:                public Map getMap() {
219:                    // assumes makeFullMapIterator() called first
220:                    return AbstractTestOrderedMap.this .map;
221:                }
222:
223:                public Map getConfirmedMap() {
224:                    // assumes makeFullMapIterator() called first
225:                    return AbstractTestOrderedMap.this .confirmed;
226:                }
227:
228:                public void verify() {
229:                    super.verify();
230:                    AbstractTestOrderedMap.this.verify();
231:                }
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.