KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > bidimap > AbstractTestSortedBidiMap


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.bidimap;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.SortedMap JavaDoc;
26 import java.util.SortedSet JavaDoc;
27 import java.util.TreeMap JavaDoc;
28 import java.util.TreeSet JavaDoc;
29
30 import org.apache.commons.collections.BulkTest;
31 import org.apache.commons.collections.SortedBidiMap;
32 import org.apache.commons.collections.map.AbstractTestSortedMap;
33
34 /**
35  * Abstract test class for {@link SortedBidiMap} methods and contracts.
36  *
37  * @version $Revision: 1.8 $ $Date: 2004/02/18 01:20:39 $
38  *
39  * @author Matthew Hawthorne
40  * @author Stephen Colebourne
41  */

42 public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiMap {
43
44     protected List JavaDoc sortedKeys = new ArrayList JavaDoc();
45     protected List JavaDoc sortedValues = new ArrayList JavaDoc();
46     protected SortedSet JavaDoc sortedNewValues = new TreeSet JavaDoc();
47
48     public AbstractTestSortedBidiMap(String JavaDoc testName) {
49         super(testName);
50         sortedKeys.addAll(Arrays.asList(getSampleKeys()));
51         Collections.sort(sortedKeys);
52         sortedKeys = Collections.unmodifiableList(sortedKeys);
53         
54         Map JavaDoc map = new TreeMap JavaDoc();
55         for (int i = 0; i < getSampleKeys().length; i++) {
56             map.put(getSampleKeys()[i], getSampleValues()[i]);
57         }
58         sortedValues.addAll(map.values());
59         sortedValues = Collections.unmodifiableList(sortedValues);
60         
61         sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
62     }
63
64     public AbstractTestSortedBidiMap() {
65         super();
66         sortedKeys.addAll(Arrays.asList(getSampleValues()));
67         Collections.sort(sortedKeys);
68         sortedKeys = Collections.unmodifiableList(sortedKeys);
69         
70         Map JavaDoc map = new TreeMap JavaDoc();
71         for (int i = 0; i < getSampleKeys().length; i++) {
72             map.put(getSampleValues()[i], getSampleKeys()[i]);
73         }
74         sortedValues.addAll(map.values());
75         sortedValues = Collections.unmodifiableList(sortedValues);
76         
77         sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
78     }
79
80     //-----------------------------------------------------------------------
81
public boolean isAllowNullKey() {
82         return false;
83     }
84     public boolean isAllowNullValue() {
85         return false;
86     }
87     public Map JavaDoc makeConfirmedMap() {
88         return new TreeMap JavaDoc();
89     }
90
91     //-----------------------------------------------------------------------
92
//-----------------------------------------------------------------------
93
public void testBidiHeadMapContains() {
94         // extra test as other tests get complex
95
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
96         Iterator JavaDoc it = sm.keySet().iterator();
97         Object JavaDoc first = it.next();
98         Object JavaDoc toKey = it.next();
99         Object JavaDoc second = it.next();
100         Object JavaDoc firstValue = sm.get(first);
101         Object JavaDoc secondValue = sm.get(second);
102         
103         SortedMap JavaDoc head = sm.headMap(toKey);
104         assertEquals(1, head.size());
105         assertEquals(true, sm.containsKey(first));
106         assertEquals(true, head.containsKey(first));
107         assertEquals(true, sm.containsValue(firstValue));
108         assertEquals(true, head.containsValue(firstValue));
109         assertEquals(true, sm.containsKey(second));
110         assertEquals(false, head.containsKey(second));
111         assertEquals(true, sm.containsValue(secondValue));
112         assertEquals(false, head.containsValue(secondValue));
113     }
114                 
115     //-----------------------------------------------------------------------
116
public void testBidiClearByHeadMap() {
117         if (isRemoveSupported() == false) return;
118         
119         // extra test as other tests get complex
120
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
121         Iterator JavaDoc it = sm.keySet().iterator();
122         Object JavaDoc first = it.next();
123         Object JavaDoc second = it.next();
124         Object JavaDoc toKey = it.next();
125         
126         Object JavaDoc firstValue = sm.get(first);
127         Object JavaDoc secondValue = sm.get(second);
128         Object JavaDoc toKeyValue = sm.get(toKey);
129         
130         SortedMap JavaDoc sub = sm.headMap(toKey);
131         int size = sm.size();
132         assertEquals(2, sub.size());
133         sub.clear();
134         assertEquals(0, sub.size());
135         assertEquals(size - 2, sm.size());
136         assertEquals(size - 2, sm.inverseBidiMap().size());
137         
138         assertEquals(false, sm.containsKey(first));
139         assertEquals(false, sm.containsValue(firstValue));
140         assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
141         assertEquals(false, sm.inverseBidiMap().containsValue(first));
142         assertEquals(false, sub.containsKey(first));
143         assertEquals(false, sub.containsValue(firstValue));
144         
145         assertEquals(false, sm.containsKey(second));
146         assertEquals(false, sm.containsValue(secondValue));
147         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
148         assertEquals(false, sm.inverseBidiMap().containsValue(second));
149         assertEquals(false, sub.containsKey(second));
150         assertEquals(false, sub.containsValue(secondValue));
151         
152         assertEquals(true, sm.containsKey(toKey));
153         assertEquals(true, sm.containsValue(toKeyValue));
154         assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
155         assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
156         assertEquals(false, sub.containsKey(toKey));
157         assertEquals(false, sub.containsValue(toKeyValue));
158     }
159
160     //-----------------------------------------------------------------------
161
public void testBidiRemoveByHeadMap() {
162         if (isRemoveSupported() == false) return;
163         
164         // extra test as other tests get complex
165
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
166         Iterator JavaDoc it = sm.keySet().iterator();
167         Object JavaDoc first = it.next();
168         Object JavaDoc second = it.next();
169         Object JavaDoc toKey = it.next();
170         
171         int size = sm.size();
172         SortedMap JavaDoc sub = sm.headMap(toKey);
173         assertEquals(2, sub.size());
174         assertEquals(true, sm.containsKey(first));
175         assertEquals(true, sub.containsKey(first));
176         assertEquals(true, sm.containsKey(second));
177         assertEquals(true, sub.containsKey(second));
178         
179         Object JavaDoc firstValue = sub.remove(first);
180         assertEquals(1, sub.size());
181         assertEquals(size - 1, sm.size());
182         assertEquals(size - 1, sm.inverseBidiMap().size());
183         assertEquals(false, sm.containsKey(first));
184         assertEquals(false, sm.containsValue(firstValue));
185         assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
186         assertEquals(false, sm.inverseBidiMap().containsValue(first));
187         assertEquals(false, sub.containsKey(first));
188         assertEquals(false, sub.containsValue(firstValue));
189         
190         Object JavaDoc secondValue = sub.remove(second);
191         assertEquals(0, sub.size());
192         assertEquals(size - 2, sm.size());
193         assertEquals(size - 2, sm.inverseBidiMap().size());
194         assertEquals(false, sm.containsKey(second));
195         assertEquals(false, sm.containsValue(secondValue));
196         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
197         assertEquals(false, sm.inverseBidiMap().containsValue(second));
198         assertEquals(false, sub.containsKey(second));
199         assertEquals(false, sub.containsValue(secondValue));
200     }
201
202     //-----------------------------------------------------------------------
203
public void testBidiRemoveByHeadMapEntrySet() {
204         if (isRemoveSupported() == false) return;
205         
206         // extra test as other tests get complex
207
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
208         Iterator JavaDoc it = sm.keySet().iterator();
209         Object JavaDoc first = it.next();
210         Object JavaDoc second = it.next();
211         Object JavaDoc toKey = it.next();
212         
213         int size = sm.size();
214         SortedMap JavaDoc sub = sm.headMap(toKey);
215         Set JavaDoc set = sub.entrySet();
216         assertEquals(2, sub.size());
217         assertEquals(2, set.size());
218         
219         Iterator JavaDoc it2 = set.iterator();
220         Map.Entry JavaDoc firstEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
221         Map.Entry JavaDoc secondEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
222         assertEquals(true, sm.containsKey(first));
223         assertEquals(true, sub.containsKey(first));
224         assertEquals(true, set.contains(firstEntry));
225         assertEquals(true, sm.containsKey(second));
226         assertEquals(true, sub.containsKey(second));
227         assertEquals(true, set.contains(secondEntry));
228         
229         set.remove(firstEntry);
230         assertEquals(1, sub.size());
231         assertEquals(size - 1, sm.size());
232         assertEquals(size - 1, sm.inverseBidiMap().size());
233         assertEquals(false, sm.containsKey(firstEntry.getKey()));
234         assertEquals(false, sm.containsValue(firstEntry.getValue()));
235         assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
236         assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
237         assertEquals(false, sub.containsKey(firstEntry.getKey()));
238         assertEquals(false, sub.containsValue(firstEntry.getValue()));
239         assertEquals(false, set.contains(firstEntry));
240         
241         set.remove(secondEntry);
242         assertEquals(0, sub.size());
243         assertEquals(size - 2, sm.size());
244         assertEquals(size - 2, sm.inverseBidiMap().size());
245         assertEquals(false, sm.containsKey(secondEntry.getKey()));
246         assertEquals(false, sm.containsValue(secondEntry.getValue()));
247         assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
248         assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
249         assertEquals(false, sub.containsKey(secondEntry.getKey()));
250         assertEquals(false, sub.containsValue(secondEntry.getValue()));
251         assertEquals(false, set.contains(secondEntry));
252     }
253
254     //-----------------------------------------------------------------------
255
//-----------------------------------------------------------------------
256
public void testBidiTailMapContains() {
257         // extra test as other tests get complex
258
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
259         Iterator JavaDoc it = sm.keySet().iterator();
260         Object JavaDoc first = it.next();
261         Object JavaDoc fromKey = it.next();
262         Object JavaDoc second = it.next();
263         Object JavaDoc firstValue = sm.get(first);
264         Object JavaDoc fromKeyValue = sm.get(fromKey);
265         Object JavaDoc secondValue = sm.get(second);
266         
267         SortedMap JavaDoc sub = sm.tailMap(fromKey);
268         assertEquals(sm.size() - 1, sub.size());
269         assertEquals(true, sm.containsKey(first));
270         assertEquals(false, sub.containsKey(first));
271         assertEquals(true, sm.containsValue(firstValue));
272         assertEquals(false, sub.containsValue(firstValue));
273         assertEquals(true, sm.containsKey(fromKey));
274         assertEquals(true, sub.containsKey(fromKey));
275         assertEquals(true, sm.containsValue(fromKeyValue));
276         assertEquals(true, sub.containsValue(fromKeyValue));
277         assertEquals(true, sm.containsKey(second));
278         assertEquals(true, sub.containsKey(second));
279         assertEquals(true, sm.containsValue(secondValue));
280         assertEquals(true, sub.containsValue(secondValue));
281     }
282
283     //-----------------------------------------------------------------------
284
public void testBidiClearByTailMap() {
285         if (isRemoveSupported() == false) return;
286         
287         // extra test as other tests get complex
288
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
289         Iterator JavaDoc it = sm.keySet().iterator();
290         it.next();
291         it.next();
292         Object JavaDoc first = it.next();
293         Object JavaDoc fromKey = it.next();
294         Object JavaDoc second = it.next();
295         
296         Object JavaDoc firstValue = sm.get(first);
297         Object JavaDoc fromKeyValue = sm.get(fromKey);
298         Object JavaDoc secondValue = sm.get(second);
299         
300         SortedMap JavaDoc sub = sm.tailMap(fromKey);
301         int size = sm.size();
302         assertEquals(size - 3, sub.size());
303         sub.clear();
304         assertEquals(0, sub.size());
305         assertEquals(3, sm.size());
306         assertEquals(3, sm.inverseBidiMap().size());
307         
308         assertEquals(true, sm.containsKey(first));
309         assertEquals(true, sm.containsValue(firstValue));
310         assertEquals(true, sm.inverseBidiMap().containsKey(firstValue));
311         assertEquals(true, sm.inverseBidiMap().containsValue(first));
312         assertEquals(false, sub.containsKey(first));
313         assertEquals(false, sub.containsValue(firstValue));
314         
315         assertEquals(false, sm.containsKey(fromKey));
316         assertEquals(false, sm.containsValue(fromKeyValue));
317         assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue));
318         assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
319         assertEquals(false, sub.containsKey(fromKey));
320         assertEquals(false, sub.containsValue(fromKeyValue));
321         
322         assertEquals(false, sm.containsKey(second));
323         assertEquals(false, sm.containsValue(secondValue));
324         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
325         assertEquals(false, sm.inverseBidiMap().containsValue(second));
326         assertEquals(false, sub.containsKey(second));
327         assertEquals(false, sub.containsValue(secondValue));
328     }
329
330     //-----------------------------------------------------------------------
331
public void testBidiRemoveByTailMap() {
332         if (isRemoveSupported() == false) return;
333         
334         // extra test as other tests get complex
335
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
336         Iterator JavaDoc it = sm.keySet().iterator();
337         it.next();
338         it.next();
339         Object JavaDoc fromKey = it.next();
340         Object JavaDoc first = it.next();
341         Object JavaDoc second = it.next();
342         
343         int size = sm.size();
344         SortedMap JavaDoc sub = sm.tailMap(fromKey);
345         assertEquals(true, sm.containsKey(first));
346         assertEquals(true, sub.containsKey(first));
347         assertEquals(true, sm.containsKey(second));
348         assertEquals(true, sub.containsKey(second));
349         
350         Object JavaDoc firstValue = sub.remove(first);
351         assertEquals(size - 3, sub.size());
352         assertEquals(size - 1, sm.size());
353         assertEquals(size - 1, sm.inverseBidiMap().size());
354         assertEquals(false, sm.containsKey(first));
355         assertEquals(false, sm.containsValue(firstValue));
356         assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
357         assertEquals(false, sm.inverseBidiMap().containsValue(first));
358         assertEquals(false, sub.containsKey(first));
359         assertEquals(false, sub.containsValue(firstValue));
360         
361         Object JavaDoc secondValue = sub.remove(second);
362         assertEquals(size - 4, sub.size());
363         assertEquals(size - 2, sm.size());
364         assertEquals(size - 2, sm.inverseBidiMap().size());
365         assertEquals(false, sm.containsKey(second));
366         assertEquals(false, sm.containsValue(secondValue));
367         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
368         assertEquals(false, sm.inverseBidiMap().containsValue(second));
369         assertEquals(false, sub.containsKey(second));
370         assertEquals(false, sub.containsValue(secondValue));
371     }
372
373     //-----------------------------------------------------------------------
374
public void testBidiRemoveByTailMapEntrySet() {
375         if (isRemoveSupported() == false) return;
376         
377         // extra test as other tests get complex
378
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
379         Iterator JavaDoc it = sm.keySet().iterator();
380         it.next();
381         it.next();
382         Object JavaDoc fromKey = it.next();
383         Object JavaDoc first = it.next();
384         Object JavaDoc second = it.next();
385         
386         int size = sm.size();
387         SortedMap JavaDoc sub = sm.tailMap(fromKey);
388         Set JavaDoc set = sub.entrySet();
389         Iterator JavaDoc it2 = set.iterator();
390         Object JavaDoc fromEntry = it2.next();
391         Map.Entry JavaDoc firstEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
392         Map.Entry JavaDoc secondEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
393         assertEquals(true, sm.containsKey(first));
394         assertEquals(true, sub.containsKey(first));
395         assertEquals(true, set.contains(firstEntry));
396         assertEquals(true, sm.containsKey(second));
397         assertEquals(true, sub.containsKey(second));
398         assertEquals(true, set.contains(secondEntry));
399         
400         set.remove(firstEntry);
401         assertEquals(size - 3, sub.size());
402         assertEquals(size - 1, sm.size());
403         assertEquals(size - 1, sm.inverseBidiMap().size());
404         assertEquals(false, sm.containsKey(firstEntry.getKey()));
405         assertEquals(false, sm.containsValue(firstEntry.getValue()));
406         assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
407         assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
408         assertEquals(false, sub.containsKey(firstEntry.getKey()));
409         assertEquals(false, sub.containsValue(firstEntry.getValue()));
410         assertEquals(false, set.contains(firstEntry));
411         
412         set.remove(secondEntry);
413         assertEquals(size - 4, sub.size());
414         assertEquals(size - 2, sm.size());
415         assertEquals(size - 2, sm.inverseBidiMap().size());
416         assertEquals(false, sm.containsKey(secondEntry.getKey()));
417         assertEquals(false, sm.containsValue(secondEntry.getValue()));
418         assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
419         assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
420         assertEquals(false, sub.containsKey(secondEntry.getKey()));
421         assertEquals(false, sub.containsValue(secondEntry.getValue()));
422         assertEquals(false, set.contains(secondEntry));
423     }
424
425     //-----------------------------------------------------------------------
426
//-----------------------------------------------------------------------
427
public void testBidiSubMapContains() {
428         // extra test as other tests get complex
429
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
430         Iterator JavaDoc it = sm.keySet().iterator();
431         Object JavaDoc first = it.next();
432         Object JavaDoc fromKey = it.next();
433         Object JavaDoc second = it.next();
434         Object JavaDoc toKey = it.next();
435         Object JavaDoc third = it.next();
436         Object JavaDoc firstValue = sm.get(first);
437         Object JavaDoc fromKeyValue = sm.get(fromKey);
438         Object JavaDoc secondValue = sm.get(second);
439         Object JavaDoc thirdValue = sm.get(third);
440         
441         SortedMap JavaDoc sub = sm.subMap(fromKey, toKey);
442         assertEquals(2, sub.size());
443         assertEquals(true, sm.containsKey(first));
444         assertEquals(false, sub.containsKey(first));
445         assertEquals(true, sm.containsValue(firstValue));
446         assertEquals(false, sub.containsValue(firstValue));
447         assertEquals(true, sm.containsKey(fromKey));
448         assertEquals(true, sub.containsKey(fromKey));
449         assertEquals(true, sm.containsValue(fromKeyValue));
450         assertEquals(true, sub.containsValue(fromKeyValue));
451         assertEquals(true, sm.containsKey(second));
452         assertEquals(true, sub.containsKey(second));
453         assertEquals(true, sm.containsValue(secondValue));
454         assertEquals(true, sub.containsValue(secondValue));
455         assertEquals(true, sm.containsKey(third));
456         assertEquals(false, sub.containsKey(third));
457         assertEquals(true, sm.containsValue(thirdValue));
458         assertEquals(false, sub.containsValue(thirdValue));
459     }
460
461     //-----------------------------------------------------------------------
462
public void testBidiClearBySubMap() {
463         if (isRemoveSupported() == false) return;
464         
465         // extra test as other tests get complex
466
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
467         Iterator JavaDoc it = sm.keySet().iterator();
468         it.next();
469         Object JavaDoc fromKey = it.next();
470         Object JavaDoc first = it.next();
471         Object JavaDoc second = it.next();
472         Object JavaDoc toKey = it.next();
473         
474         Object JavaDoc fromKeyValue = sm.get(fromKey);
475         Object JavaDoc firstValue = sm.get(first);
476         Object JavaDoc secondValue = sm.get(second);
477         Object JavaDoc toKeyValue = sm.get(toKey);
478         
479         SortedMap JavaDoc sub = sm.subMap(fromKey, toKey);
480         int size = sm.size();
481         assertEquals(3, sub.size());
482         sub.clear();
483         assertEquals(0, sub.size());
484         assertEquals(size - 3, sm.size());
485         assertEquals(size - 3, sm.inverseBidiMap().size());
486         
487         assertEquals(false, sm.containsKey(fromKey));
488         assertEquals(false, sm.containsValue(fromKeyValue));
489         assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue));
490         assertEquals(false, sm.inverseBidiMap().containsValue(fromKey));
491         assertEquals(false, sub.containsKey(fromKey));
492         assertEquals(false, sub.containsValue(fromKeyValue));
493         
494         assertEquals(false, sm.containsKey(first));
495         assertEquals(false, sm.containsValue(firstValue));
496         assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
497         assertEquals(false, sm.inverseBidiMap().containsValue(first));
498         assertEquals(false, sub.containsKey(first));
499         assertEquals(false, sub.containsValue(firstValue));
500         
501         assertEquals(false, sm.containsKey(second));
502         assertEquals(false, sm.containsValue(secondValue));
503         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
504         assertEquals(false, sm.inverseBidiMap().containsValue(second));
505         assertEquals(false, sub.containsKey(second));
506         assertEquals(false, sub.containsValue(secondValue));
507         
508         assertEquals(true, sm.containsKey(toKey));
509         assertEquals(true, sm.containsValue(toKeyValue));
510         assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue));
511         assertEquals(true, sm.inverseBidiMap().containsValue(toKey));
512         assertEquals(false, sub.containsKey(toKey));
513         assertEquals(false, sub.containsValue(toKeyValue));
514     }
515
516     //-----------------------------------------------------------------------
517
public void testBidiRemoveBySubMap() {
518         if (isRemoveSupported() == false) return;
519         
520         // extra test as other tests get complex
521
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
522         Iterator JavaDoc it = sm.keySet().iterator();
523         it.next();
524         it.next();
525         Object JavaDoc fromKey = it.next();
526         Object JavaDoc first = it.next();
527         Object JavaDoc second = it.next();
528         Object JavaDoc toKey = it.next();
529         
530         int size = sm.size();
531         SortedMap JavaDoc sub = sm.subMap(fromKey, toKey);
532         assertEquals(true, sm.containsKey(first));
533         assertEquals(true, sub.containsKey(first));
534         assertEquals(true, sm.containsKey(second));
535         assertEquals(true, sub.containsKey(second));
536         
537         Object JavaDoc firstValue = sub.remove(first);
538         assertEquals(2, sub.size());
539         assertEquals(size - 1, sm.size());
540         assertEquals(size - 1, sm.inverseBidiMap().size());
541         assertEquals(false, sm.containsKey(first));
542         assertEquals(false, sm.containsValue(firstValue));
543         assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
544         assertEquals(false, sm.inverseBidiMap().containsValue(first));
545         assertEquals(false, sub.containsKey(first));
546         assertEquals(false, sub.containsValue(firstValue));
547         
548         Object JavaDoc secondValue = sub.remove(second);
549         assertEquals(1, sub.size());
550         assertEquals(size - 2, sm.size());
551         assertEquals(size - 2, sm.inverseBidiMap().size());
552         assertEquals(false, sm.containsKey(second));
553         assertEquals(false, sm.containsValue(secondValue));
554         assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
555         assertEquals(false, sm.inverseBidiMap().containsValue(second));
556         assertEquals(false, sub.containsKey(second));
557         assertEquals(false, sub.containsValue(secondValue));
558     }
559
560     //-----------------------------------------------------------------------
561
public void testBidiRemoveBySubMapEntrySet() {
562         if (isRemoveSupported() == false) return;
563         
564         // extra test as other tests get complex
565
SortedBidiMap sm = (SortedBidiMap) makeFullMap();
566         Iterator JavaDoc it = sm.keySet().iterator();
567         it.next();
568         it.next();
569         Object JavaDoc fromKey = it.next();
570         Object JavaDoc first = it.next();
571         Object JavaDoc second = it.next();
572         Object JavaDoc toKey = it.next();
573         
574         int size = sm.size();
575         SortedMap JavaDoc sub = sm.subMap(fromKey, toKey);
576         Set JavaDoc set = sub.entrySet();
577         assertEquals(3, set.size());
578         Iterator JavaDoc it2 = set.iterator();
579         Object JavaDoc fromEntry = it2.next();
580         Map.Entry JavaDoc firstEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
581         Map.Entry JavaDoc secondEntry = cloneMapEntry((Map.Entry JavaDoc) it2.next());
582         assertEquals(true, sm.containsKey(first));
583         assertEquals(true, sub.containsKey(first));
584         assertEquals(true, set.contains(firstEntry));
585         assertEquals(true, sm.containsKey(second));
586         assertEquals(true, sub.containsKey(second));
587         assertEquals(true, set.contains(secondEntry));
588         
589         set.remove(firstEntry);
590         assertEquals(2, sub.size());
591         assertEquals(size - 1, sm.size());
592         assertEquals(size - 1, sm.inverseBidiMap().size());
593         assertEquals(false, sm.containsKey(firstEntry.getKey()));
594         assertEquals(false, sm.containsValue(firstEntry.getValue()));
595         assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
596         assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
597         assertEquals(false, sub.containsKey(firstEntry.getKey()));
598         assertEquals(false, sub.containsValue(firstEntry.getValue()));
599         assertEquals(false, set.contains(firstEntry));
600         
601         set.remove(secondEntry);
602         assertEquals(1, sub.size());
603         assertEquals(size - 2, sm.size());
604         assertEquals(size - 2, sm.inverseBidiMap().size());
605         assertEquals(false, sm.containsKey(secondEntry.getKey()));
606         assertEquals(false, sm.containsValue(secondEntry.getValue()));
607         assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
608         assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
609         assertEquals(false, sub.containsKey(secondEntry.getKey()));
610         assertEquals(false, sub.containsValue(secondEntry.getValue()));
611         assertEquals(false, set.contains(secondEntry));
612     }
613
614     //-----------------------------------------------------------------------
615
public BulkTest bulkTestHeadMap() {
616         return new AbstractTestSortedMap.TestHeadMap(this);
617     }
618
619     public BulkTest bulkTestTailMap() {
620         return new AbstractTestSortedMap.TestTailMap(this);
621     }
622
623     public BulkTest bulkTestSubMap() {
624         return new AbstractTestSortedMap.TestSubMap(this);
625     }
626
627 }
628
Popular Tags