Source Code Cross Referenced for AbstractTestSortedBidiMap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » bidimap » 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.bidimap 
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.bidimap;
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.Set;
025:        import java.util.SortedMap;
026:        import java.util.SortedSet;
027:        import java.util.TreeMap;
028:        import java.util.TreeSet;
029:
030:        import org.apache.commons.collections.BulkTest;
031:        import org.apache.commons.collections.SortedBidiMap;
032:        import org.apache.commons.collections.map.AbstractTestSortedMap;
033:
034:        /**
035:         * Abstract test class for {@link SortedBidiMap} methods and contracts.
036:         * 
037:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
038:         * 
039:         * @author Matthew Hawthorne
040:         * @author Stephen Colebourne
041:         */
042:        public abstract class AbstractTestSortedBidiMap extends
043:                AbstractTestOrderedBidiMap {
044:
045:            protected List sortedKeys = new ArrayList();
046:            protected List sortedValues = new ArrayList();
047:            protected SortedSet sortedNewValues = new TreeSet();
048:
049:            public AbstractTestSortedBidiMap(String testName) {
050:                super (testName);
051:                sortedKeys.addAll(Arrays.asList(getSampleKeys()));
052:                Collections.sort(sortedKeys);
053:                sortedKeys = Collections.unmodifiableList(sortedKeys);
054:
055:                Map map = new TreeMap();
056:                for (int i = 0; i < getSampleKeys().length; i++) {
057:                    map.put(getSampleKeys()[i], getSampleValues()[i]);
058:                }
059:                sortedValues.addAll(map.values());
060:                sortedValues = Collections.unmodifiableList(sortedValues);
061:
062:                sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
063:            }
064:
065:            public AbstractTestSortedBidiMap() {
066:                super ();
067:                sortedKeys.addAll(Arrays.asList(getSampleValues()));
068:                Collections.sort(sortedKeys);
069:                sortedKeys = Collections.unmodifiableList(sortedKeys);
070:
071:                Map map = new TreeMap();
072:                for (int i = 0; i < getSampleKeys().length; i++) {
073:                    map.put(getSampleValues()[i], getSampleKeys()[i]);
074:                }
075:                sortedValues.addAll(map.values());
076:                sortedValues = Collections.unmodifiableList(sortedValues);
077:
078:                sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
079:            }
080:
081:            //-----------------------------------------------------------------------
082:            public boolean isAllowNullKey() {
083:                return false;
084:            }
085:
086:            public boolean isAllowNullValue() {
087:                return false;
088:            }
089:
090:            public Map makeConfirmedMap() {
091:                return new TreeMap();
092:            }
093:
094:            //-----------------------------------------------------------------------
095:            //-----------------------------------------------------------------------
096:            public void testBidiHeadMapContains() {
097:                // extra test as other tests get complex
098:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
099:                Iterator it = sm.keySet().iterator();
100:                Object first = it.next();
101:                Object toKey = it.next();
102:                Object second = it.next();
103:                Object firstValue = sm.get(first);
104:                Object secondValue = sm.get(second);
105:
106:                SortedMap head = sm.headMap(toKey);
107:                assertEquals(1, head.size());
108:                assertEquals(true, sm.containsKey(first));
109:                assertEquals(true, head.containsKey(first));
110:                assertEquals(true, sm.containsValue(firstValue));
111:                assertEquals(true, head.containsValue(firstValue));
112:                assertEquals(true, sm.containsKey(second));
113:                assertEquals(false, head.containsKey(second));
114:                assertEquals(true, sm.containsValue(secondValue));
115:                assertEquals(false, head.containsValue(secondValue));
116:            }
117:
118:            //-----------------------------------------------------------------------
119:            public void testBidiClearByHeadMap() {
120:                if (isRemoveSupported() == false)
121:                    return;
122:
123:                // extra test as other tests get complex
124:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
125:                Iterator it = sm.keySet().iterator();
126:                Object first = it.next();
127:                Object second = it.next();
128:                Object toKey = it.next();
129:
130:                Object firstValue = sm.get(first);
131:                Object secondValue = sm.get(second);
132:                Object toKeyValue = sm.get(toKey);
133:
134:                SortedMap sub = sm.headMap(toKey);
135:                int size = sm.size();
136:                assertEquals(2, sub.size());
137:                sub.clear();
138:                assertEquals(0, sub.size());
139:                assertEquals(size - 2, sm.size());
140:                assertEquals(size - 2, sm.inverseBidiMap().size());
141:
142:                assertEquals(false, sm.containsKey(first));
143:                assertEquals(false, sm.containsValue(firstValue));
144:                assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
145:                assertEquals(false, sm.inverseBidiMap().containsValue(first));
146:                assertEquals(false, sub.containsKey(first));
147:                assertEquals(false, sub.containsValue(firstValue));
148:
149:                assertEquals(false, sm.containsKey(second));
150:                assertEquals(false, sm.containsValue(secondValue));
151:                assertEquals(false, sm.inverseBidiMap()
152:                        .containsKey(secondValue));
153:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
154:                assertEquals(false, sub.containsKey(second));
155:                assertEquals(false, sub.containsValue(secondValue));
156:
157:                assertEquals(true, sm.containsKey(toKey));
158:                assertEquals(true, sm.containsValue(toKeyValue));
159:                assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
160:                assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
161:                assertEquals(false, sub.containsKey(toKey));
162:                assertEquals(false, sub.containsValue(toKeyValue));
163:            }
164:
165:            //-----------------------------------------------------------------------
166:            public void testBidiRemoveByHeadMap() {
167:                if (isRemoveSupported() == false)
168:                    return;
169:
170:                // extra test as other tests get complex
171:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
172:                Iterator it = sm.keySet().iterator();
173:                Object first = it.next();
174:                Object second = it.next();
175:                Object toKey = it.next();
176:
177:                int size = sm.size();
178:                SortedMap sub = sm.headMap(toKey);
179:                assertEquals(2, sub.size());
180:                assertEquals(true, sm.containsKey(first));
181:                assertEquals(true, sub.containsKey(first));
182:                assertEquals(true, sm.containsKey(second));
183:                assertEquals(true, sub.containsKey(second));
184:
185:                Object firstValue = sub.remove(first);
186:                assertEquals(1, sub.size());
187:                assertEquals(size - 1, sm.size());
188:                assertEquals(size - 1, sm.inverseBidiMap().size());
189:                assertEquals(false, sm.containsKey(first));
190:                assertEquals(false, sm.containsValue(firstValue));
191:                assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
192:                assertEquals(false, sm.inverseBidiMap().containsValue(first));
193:                assertEquals(false, sub.containsKey(first));
194:                assertEquals(false, sub.containsValue(firstValue));
195:
196:                Object secondValue = sub.remove(second);
197:                assertEquals(0, sub.size());
198:                assertEquals(size - 2, sm.size());
199:                assertEquals(size - 2, sm.inverseBidiMap().size());
200:                assertEquals(false, sm.containsKey(second));
201:                assertEquals(false, sm.containsValue(secondValue));
202:                assertEquals(false, sm.inverseBidiMap()
203:                        .containsKey(secondValue));
204:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
205:                assertEquals(false, sub.containsKey(second));
206:                assertEquals(false, sub.containsValue(secondValue));
207:            }
208:
209:            //-----------------------------------------------------------------------
210:            public void testBidiRemoveByHeadMapEntrySet() {
211:                if (isRemoveSupported() == false)
212:                    return;
213:
214:                // extra test as other tests get complex
215:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
216:                Iterator it = sm.keySet().iterator();
217:                Object first = it.next();
218:                Object second = it.next();
219:                Object toKey = it.next();
220:
221:                int size = sm.size();
222:                SortedMap sub = sm.headMap(toKey);
223:                Set set = sub.entrySet();
224:                assertEquals(2, sub.size());
225:                assertEquals(2, set.size());
226:
227:                Iterator it2 = set.iterator();
228:                Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next());
229:                Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next());
230:                assertEquals(true, sm.containsKey(first));
231:                assertEquals(true, sub.containsKey(first));
232:                assertEquals(true, set.contains(firstEntry));
233:                assertEquals(true, sm.containsKey(second));
234:                assertEquals(true, sub.containsKey(second));
235:                assertEquals(true, set.contains(secondEntry));
236:
237:                set.remove(firstEntry);
238:                assertEquals(1, sub.size());
239:                assertEquals(size - 1, sm.size());
240:                assertEquals(size - 1, sm.inverseBidiMap().size());
241:                assertEquals(false, sm.containsKey(firstEntry.getKey()));
242:                assertEquals(false, sm.containsValue(firstEntry.getValue()));
243:                assertEquals(false, sm.inverseBidiMap().containsKey(
244:                        firstEntry.getValue()));
245:                assertEquals(false, sm.inverseBidiMap().containsValue(
246:                        firstEntry.getKey()));
247:                assertEquals(false, sub.containsKey(firstEntry.getKey()));
248:                assertEquals(false, sub.containsValue(firstEntry.getValue()));
249:                assertEquals(false, set.contains(firstEntry));
250:
251:                set.remove(secondEntry);
252:                assertEquals(0, sub.size());
253:                assertEquals(size - 2, sm.size());
254:                assertEquals(size - 2, sm.inverseBidiMap().size());
255:                assertEquals(false, sm.containsKey(secondEntry.getKey()));
256:                assertEquals(false, sm.containsValue(secondEntry.getValue()));
257:                assertEquals(false, sm.inverseBidiMap().containsKey(
258:                        secondEntry.getValue()));
259:                assertEquals(false, sm.inverseBidiMap().containsValue(
260:                        secondEntry.getKey()));
261:                assertEquals(false, sub.containsKey(secondEntry.getKey()));
262:                assertEquals(false, sub.containsValue(secondEntry.getValue()));
263:                assertEquals(false, set.contains(secondEntry));
264:            }
265:
266:            //-----------------------------------------------------------------------
267:            //-----------------------------------------------------------------------
268:            public void testBidiTailMapContains() {
269:                // extra test as other tests get complex
270:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
271:                Iterator it = sm.keySet().iterator();
272:                Object first = it.next();
273:                Object fromKey = it.next();
274:                Object second = it.next();
275:                Object firstValue = sm.get(first);
276:                Object fromKeyValue = sm.get(fromKey);
277:                Object secondValue = sm.get(second);
278:
279:                SortedMap sub = sm.tailMap(fromKey);
280:                assertEquals(sm.size() - 1, sub.size());
281:                assertEquals(true, sm.containsKey(first));
282:                assertEquals(false, sub.containsKey(first));
283:                assertEquals(true, sm.containsValue(firstValue));
284:                assertEquals(false, sub.containsValue(firstValue));
285:                assertEquals(true, sm.containsKey(fromKey));
286:                assertEquals(true, sub.containsKey(fromKey));
287:                assertEquals(true, sm.containsValue(fromKeyValue));
288:                assertEquals(true, sub.containsValue(fromKeyValue));
289:                assertEquals(true, sm.containsKey(second));
290:                assertEquals(true, sub.containsKey(second));
291:                assertEquals(true, sm.containsValue(secondValue));
292:                assertEquals(true, sub.containsValue(secondValue));
293:            }
294:
295:            //-----------------------------------------------------------------------
296:            public void testBidiClearByTailMap() {
297:                if (isRemoveSupported() == false)
298:                    return;
299:
300:                // extra test as other tests get complex
301:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
302:                Iterator it = sm.keySet().iterator();
303:                it.next();
304:                it.next();
305:                Object first = it.next();
306:                Object fromKey = it.next();
307:                Object second = it.next();
308:
309:                Object firstValue = sm.get(first);
310:                Object fromKeyValue = sm.get(fromKey);
311:                Object secondValue = sm.get(second);
312:
313:                SortedMap sub = sm.tailMap(fromKey);
314:                int size = sm.size();
315:                assertEquals(size - 3, sub.size());
316:                sub.clear();
317:                assertEquals(0, sub.size());
318:                assertEquals(3, sm.size());
319:                assertEquals(3, sm.inverseBidiMap().size());
320:
321:                assertEquals(true, sm.containsKey(first));
322:                assertEquals(true, sm.containsValue(firstValue));
323:                assertEquals(true, sm.inverseBidiMap().containsKey(firstValue));
324:                assertEquals(true, sm.inverseBidiMap().containsValue(first));
325:                assertEquals(false, sub.containsKey(first));
326:                assertEquals(false, sub.containsValue(firstValue));
327:
328:                assertEquals(false, sm.containsKey(fromKey));
329:                assertEquals(false, sm.containsValue(fromKeyValue));
330:                assertEquals(false, sm.inverseBidiMap().containsKey(
331:                        fromKeyValue));
332:                assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
333:                assertEquals(false, sub.containsKey(fromKey));
334:                assertEquals(false, sub.containsValue(fromKeyValue));
335:
336:                assertEquals(false, sm.containsKey(second));
337:                assertEquals(false, sm.containsValue(secondValue));
338:                assertEquals(false, sm.inverseBidiMap()
339:                        .containsKey(secondValue));
340:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
341:                assertEquals(false, sub.containsKey(second));
342:                assertEquals(false, sub.containsValue(secondValue));
343:            }
344:
345:            //-----------------------------------------------------------------------                
346:            public void testBidiRemoveByTailMap() {
347:                if (isRemoveSupported() == false)
348:                    return;
349:
350:                // extra test as other tests get complex
351:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
352:                Iterator it = sm.keySet().iterator();
353:                it.next();
354:                it.next();
355:                Object fromKey = it.next();
356:                Object first = it.next();
357:                Object second = it.next();
358:
359:                int size = sm.size();
360:                SortedMap sub = sm.tailMap(fromKey);
361:                assertEquals(true, sm.containsKey(first));
362:                assertEquals(true, sub.containsKey(first));
363:                assertEquals(true, sm.containsKey(second));
364:                assertEquals(true, sub.containsKey(second));
365:
366:                Object firstValue = sub.remove(first);
367:                assertEquals(size - 3, sub.size());
368:                assertEquals(size - 1, sm.size());
369:                assertEquals(size - 1, sm.inverseBidiMap().size());
370:                assertEquals(false, sm.containsKey(first));
371:                assertEquals(false, sm.containsValue(firstValue));
372:                assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
373:                assertEquals(false, sm.inverseBidiMap().containsValue(first));
374:                assertEquals(false, sub.containsKey(first));
375:                assertEquals(false, sub.containsValue(firstValue));
376:
377:                Object secondValue = sub.remove(second);
378:                assertEquals(size - 4, sub.size());
379:                assertEquals(size - 2, sm.size());
380:                assertEquals(size - 2, sm.inverseBidiMap().size());
381:                assertEquals(false, sm.containsKey(second));
382:                assertEquals(false, sm.containsValue(secondValue));
383:                assertEquals(false, sm.inverseBidiMap()
384:                        .containsKey(secondValue));
385:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
386:                assertEquals(false, sub.containsKey(second));
387:                assertEquals(false, sub.containsValue(secondValue));
388:            }
389:
390:            //-----------------------------------------------------------------------
391:            public void testBidiRemoveByTailMapEntrySet() {
392:                if (isRemoveSupported() == false)
393:                    return;
394:
395:                // extra test as other tests get complex
396:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
397:                Iterator it = sm.keySet().iterator();
398:                it.next();
399:                it.next();
400:                Object fromKey = it.next();
401:                Object first = it.next();
402:                Object second = it.next();
403:
404:                int size = sm.size();
405:                SortedMap sub = sm.tailMap(fromKey);
406:                Set set = sub.entrySet();
407:                Iterator it2 = set.iterator();
408:                Object fromEntry = it2.next();
409:                Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next());
410:                Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next());
411:                assertEquals(true, sm.containsKey(first));
412:                assertEquals(true, sub.containsKey(first));
413:                assertEquals(true, set.contains(firstEntry));
414:                assertEquals(true, sm.containsKey(second));
415:                assertEquals(true, sub.containsKey(second));
416:                assertEquals(true, set.contains(secondEntry));
417:
418:                set.remove(firstEntry);
419:                assertEquals(size - 3, sub.size());
420:                assertEquals(size - 1, sm.size());
421:                assertEquals(size - 1, sm.inverseBidiMap().size());
422:                assertEquals(false, sm.containsKey(firstEntry.getKey()));
423:                assertEquals(false, sm.containsValue(firstEntry.getValue()));
424:                assertEquals(false, sm.inverseBidiMap().containsKey(
425:                        firstEntry.getValue()));
426:                assertEquals(false, sm.inverseBidiMap().containsValue(
427:                        firstEntry.getKey()));
428:                assertEquals(false, sub.containsKey(firstEntry.getKey()));
429:                assertEquals(false, sub.containsValue(firstEntry.getValue()));
430:                assertEquals(false, set.contains(firstEntry));
431:
432:                set.remove(secondEntry);
433:                assertEquals(size - 4, sub.size());
434:                assertEquals(size - 2, sm.size());
435:                assertEquals(size - 2, sm.inverseBidiMap().size());
436:                assertEquals(false, sm.containsKey(secondEntry.getKey()));
437:                assertEquals(false, sm.containsValue(secondEntry.getValue()));
438:                assertEquals(false, sm.inverseBidiMap().containsKey(
439:                        secondEntry.getValue()));
440:                assertEquals(false, sm.inverseBidiMap().containsValue(
441:                        secondEntry.getKey()));
442:                assertEquals(false, sub.containsKey(secondEntry.getKey()));
443:                assertEquals(false, sub.containsValue(secondEntry.getValue()));
444:                assertEquals(false, set.contains(secondEntry));
445:            }
446:
447:            //-----------------------------------------------------------------------
448:            //-----------------------------------------------------------------------
449:            public void testBidiSubMapContains() {
450:                // extra test as other tests get complex
451:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
452:                Iterator it = sm.keySet().iterator();
453:                Object first = it.next();
454:                Object fromKey = it.next();
455:                Object second = it.next();
456:                Object toKey = it.next();
457:                Object third = it.next();
458:                Object firstValue = sm.get(first);
459:                Object fromKeyValue = sm.get(fromKey);
460:                Object secondValue = sm.get(second);
461:                Object thirdValue = sm.get(third);
462:
463:                SortedMap sub = sm.subMap(fromKey, toKey);
464:                assertEquals(2, sub.size());
465:                assertEquals(true, sm.containsKey(first));
466:                assertEquals(false, sub.containsKey(first));
467:                assertEquals(true, sm.containsValue(firstValue));
468:                assertEquals(false, sub.containsValue(firstValue));
469:                assertEquals(true, sm.containsKey(fromKey));
470:                assertEquals(true, sub.containsKey(fromKey));
471:                assertEquals(true, sm.containsValue(fromKeyValue));
472:                assertEquals(true, sub.containsValue(fromKeyValue));
473:                assertEquals(true, sm.containsKey(second));
474:                assertEquals(true, sub.containsKey(second));
475:                assertEquals(true, sm.containsValue(secondValue));
476:                assertEquals(true, sub.containsValue(secondValue));
477:                assertEquals(true, sm.containsKey(third));
478:                assertEquals(false, sub.containsKey(third));
479:                assertEquals(true, sm.containsValue(thirdValue));
480:                assertEquals(false, sub.containsValue(thirdValue));
481:            }
482:
483:            //-----------------------------------------------------------------------
484:            public void testBidiClearBySubMap() {
485:                if (isRemoveSupported() == false)
486:                    return;
487:
488:                // extra test as other tests get complex
489:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
490:                Iterator it = sm.keySet().iterator();
491:                it.next();
492:                Object fromKey = it.next();
493:                Object first = it.next();
494:                Object second = it.next();
495:                Object toKey = it.next();
496:
497:                Object fromKeyValue = sm.get(fromKey);
498:                Object firstValue = sm.get(first);
499:                Object secondValue = sm.get(second);
500:                Object toKeyValue = sm.get(toKey);
501:
502:                SortedMap sub = sm.subMap(fromKey, toKey);
503:                int size = sm.size();
504:                assertEquals(3, sub.size());
505:                sub.clear();
506:                assertEquals(0, sub.size());
507:                assertEquals(size - 3, sm.size());
508:                assertEquals(size - 3, sm.inverseBidiMap().size());
509:
510:                assertEquals(false, sm.containsKey(fromKey));
511:                assertEquals(false, sm.containsValue(fromKeyValue));
512:                assertEquals(false, sm.inverseBidiMap().containsKey(
513:                        fromKeyValue));
514:                assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
515:                assertEquals(false, sub.containsKey(fromKey));
516:                assertEquals(false, sub.containsValue(fromKeyValue));
517:
518:                assertEquals(false, sm.containsKey(first));
519:                assertEquals(false, sm.containsValue(firstValue));
520:                assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
521:                assertEquals(false, sm.inverseBidiMap().containsValue(first));
522:                assertEquals(false, sub.containsKey(first));
523:                assertEquals(false, sub.containsValue(firstValue));
524:
525:                assertEquals(false, sm.containsKey(second));
526:                assertEquals(false, sm.containsValue(secondValue));
527:                assertEquals(false, sm.inverseBidiMap()
528:                        .containsKey(secondValue));
529:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
530:                assertEquals(false, sub.containsKey(second));
531:                assertEquals(false, sub.containsValue(secondValue));
532:
533:                assertEquals(true, sm.containsKey(toKey));
534:                assertEquals(true, sm.containsValue(toKeyValue));
535:                assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
536:                assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
537:                assertEquals(false, sub.containsKey(toKey));
538:                assertEquals(false, sub.containsValue(toKeyValue));
539:            }
540:
541:            //-----------------------------------------------------------------------
542:            public void testBidiRemoveBySubMap() {
543:                if (isRemoveSupported() == false)
544:                    return;
545:
546:                // extra test as other tests get complex
547:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
548:                Iterator it = sm.keySet().iterator();
549:                it.next();
550:                it.next();
551:                Object fromKey = it.next();
552:                Object first = it.next();
553:                Object second = it.next();
554:                Object toKey = it.next();
555:
556:                int size = sm.size();
557:                SortedMap sub = sm.subMap(fromKey, toKey);
558:                assertEquals(true, sm.containsKey(first));
559:                assertEquals(true, sub.containsKey(first));
560:                assertEquals(true, sm.containsKey(second));
561:                assertEquals(true, sub.containsKey(second));
562:
563:                Object firstValue = sub.remove(first);
564:                assertEquals(2, sub.size());
565:                assertEquals(size - 1, sm.size());
566:                assertEquals(size - 1, sm.inverseBidiMap().size());
567:                assertEquals(false, sm.containsKey(first));
568:                assertEquals(false, sm.containsValue(firstValue));
569:                assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
570:                assertEquals(false, sm.inverseBidiMap().containsValue(first));
571:                assertEquals(false, sub.containsKey(first));
572:                assertEquals(false, sub.containsValue(firstValue));
573:
574:                Object secondValue = sub.remove(second);
575:                assertEquals(1, sub.size());
576:                assertEquals(size - 2, sm.size());
577:                assertEquals(size - 2, sm.inverseBidiMap().size());
578:                assertEquals(false, sm.containsKey(second));
579:                assertEquals(false, sm.containsValue(secondValue));
580:                assertEquals(false, sm.inverseBidiMap()
581:                        .containsKey(secondValue));
582:                assertEquals(false, sm.inverseBidiMap().containsValue(second));
583:                assertEquals(false, sub.containsKey(second));
584:                assertEquals(false, sub.containsValue(secondValue));
585:            }
586:
587:            //-----------------------------------------------------------------------
588:            public void testBidiRemoveBySubMapEntrySet() {
589:                if (isRemoveSupported() == false)
590:                    return;
591:
592:                // extra test as other tests get complex
593:                SortedBidiMap sm = (SortedBidiMap) makeFullMap();
594:                Iterator it = sm.keySet().iterator();
595:                it.next();
596:                it.next();
597:                Object fromKey = it.next();
598:                Object first = it.next();
599:                Object second = it.next();
600:                Object toKey = it.next();
601:
602:                int size = sm.size();
603:                SortedMap sub = sm.subMap(fromKey, toKey);
604:                Set set = sub.entrySet();
605:                assertEquals(3, set.size());
606:                Iterator it2 = set.iterator();
607:                Object fromEntry = it2.next();
608:                Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next());
609:                Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next());
610:                assertEquals(true, sm.containsKey(first));
611:                assertEquals(true, sub.containsKey(first));
612:                assertEquals(true, set.contains(firstEntry));
613:                assertEquals(true, sm.containsKey(second));
614:                assertEquals(true, sub.containsKey(second));
615:                assertEquals(true, set.contains(secondEntry));
616:
617:                set.remove(firstEntry);
618:                assertEquals(2, sub.size());
619:                assertEquals(size - 1, sm.size());
620:                assertEquals(size - 1, sm.inverseBidiMap().size());
621:                assertEquals(false, sm.containsKey(firstEntry.getKey()));
622:                assertEquals(false, sm.containsValue(firstEntry.getValue()));
623:                assertEquals(false, sm.inverseBidiMap().containsKey(
624:                        firstEntry.getValue()));
625:                assertEquals(false, sm.inverseBidiMap().containsValue(
626:                        firstEntry.getKey()));
627:                assertEquals(false, sub.containsKey(firstEntry.getKey()));
628:                assertEquals(false, sub.containsValue(firstEntry.getValue()));
629:                assertEquals(false, set.contains(firstEntry));
630:
631:                set.remove(secondEntry);
632:                assertEquals(1, sub.size());
633:                assertEquals(size - 2, sm.size());
634:                assertEquals(size - 2, sm.inverseBidiMap().size());
635:                assertEquals(false, sm.containsKey(secondEntry.getKey()));
636:                assertEquals(false, sm.containsValue(secondEntry.getValue()));
637:                assertEquals(false, sm.inverseBidiMap().containsKey(
638:                        secondEntry.getValue()));
639:                assertEquals(false, sm.inverseBidiMap().containsValue(
640:                        secondEntry.getKey()));
641:                assertEquals(false, sub.containsKey(secondEntry.getKey()));
642:                assertEquals(false, sub.containsValue(secondEntry.getValue()));
643:                assertEquals(false, set.contains(secondEntry));
644:            }
645:
646:            //-----------------------------------------------------------------------    
647:            public BulkTest bulkTestHeadMap() {
648:                return new AbstractTestSortedMap.TestHeadMap(this );
649:            }
650:
651:            public BulkTest bulkTestTailMap() {
652:                return new AbstractTestSortedMap.TestTailMap(this );
653:            }
654:
655:            public BulkTest bulkTestSubMap() {
656:                return new AbstractTestSortedMap.TestSubMap(this);
657:            }
658:
659:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.