1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
11 |
|
|
12 |
|
public class TreeSubSetTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
< |
return new TestSuite(TreeSubSetTest.class); |
17 |
> |
return new TestSuite(TreeSubSetTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
static class MyReverseComparator implements Comparator { |
21 |
|
public int compare(Object x, Object y) { |
22 |
< |
int i = ((Integer)x).intValue(); |
23 |
< |
int j = ((Integer)y).intValue(); |
24 |
< |
if (i < j) return 1; |
25 |
< |
if (i > j) return -1; |
26 |
< |
return 0; |
22 |
> |
return ((Comparable)y).compareTo(x); |
23 |
|
} |
24 |
|
} |
25 |
|
|
27 |
|
* Create a set of given size containing consecutive |
28 |
|
* Integers 0 ... n. |
29 |
|
*/ |
30 |
< |
private NavigableSet populatedSet(int n) { |
31 |
< |
TreeSet q = new TreeSet(); |
30 |
> |
private NavigableSet<Integer> populatedSet(int n) { |
31 |
> |
TreeSet<Integer> q = new TreeSet<Integer>(); |
32 |
|
assertTrue(q.isEmpty()); |
33 |
|
|
34 |
< |
for (int i = n-1; i >= 0; i-=2) |
35 |
< |
assertTrue(q.add(new Integer(i))); |
36 |
< |
for (int i = (n & 1); i < n; i+=2) |
37 |
< |
assertTrue(q.add(new Integer(i))); |
34 |
> |
for (int i = n-1; i >= 0; i-=2) |
35 |
> |
assertTrue(q.add(new Integer(i))); |
36 |
> |
for (int i = (n & 1); i < n; i+=2) |
37 |
> |
assertTrue(q.add(new Integer(i))); |
38 |
|
assertTrue(q.add(new Integer(-n))); |
39 |
|
assertTrue(q.add(new Integer(n))); |
40 |
|
NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false); |
41 |
|
assertFalse(s.isEmpty()); |
42 |
< |
assertEquals(n, s.size()); |
42 |
> |
assertEquals(n, s.size()); |
43 |
|
return s; |
44 |
|
} |
45 |
|
|
57 |
|
q.add(zero); |
58 |
|
q.add(seven); |
59 |
|
NavigableSet s = q.subSet(one, true, seven, false); |
60 |
< |
assertEquals(5, s.size()); |
60 |
> |
assertEquals(5, s.size()); |
61 |
|
return s; |
62 |
|
} |
63 |
|
|
70 |
|
q.add(m4); |
71 |
|
q.add(m5); |
72 |
|
NavigableSet s = q.descendingSet(); |
73 |
< |
assertEquals(5, s.size()); |
73 |
> |
assertEquals(5, s.size()); |
74 |
|
return s; |
75 |
|
} |
76 |
|
|
77 |
|
private static NavigableSet set0() { |
78 |
< |
TreeSet set = new TreeSet(); |
78 |
> |
TreeSet set = new TreeSet(); |
79 |
|
assertTrue(set.isEmpty()); |
80 |
|
return set.tailSet(m1, false); |
81 |
|
} |
82 |
|
|
83 |
|
private static NavigableSet dset0() { |
84 |
< |
TreeSet set = new TreeSet(); |
84 |
> |
TreeSet set = new TreeSet(); |
85 |
|
assertTrue(set.isEmpty()); |
86 |
|
return set; |
87 |
|
} |
100 |
|
public void testEmpty() { |
101 |
|
NavigableSet q = set0(); |
102 |
|
assertTrue(q.isEmpty()); |
103 |
< |
q.add(new Integer(1)); |
103 |
> |
assertTrue(q.add(new Integer(1))); |
104 |
|
assertFalse(q.isEmpty()); |
105 |
< |
q.add(new Integer(2)); |
105 |
> |
assertTrue(q.add(new Integer(2))); |
106 |
|
q.pollFirst(); |
107 |
|
q.pollFirst(); |
108 |
|
assertTrue(q.isEmpty()); |
127 |
|
* add(null) throws NPE |
128 |
|
*/ |
129 |
|
public void testAddNull() { |
130 |
< |
try { |
130 |
> |
try { |
131 |
|
NavigableSet q = set0(); |
132 |
|
q.add(null); |
133 |
|
shouldThrow(); |
134 |
< |
} catch (NullPointerException success) { } |
134 |
> |
} catch (NullPointerException success) {} |
135 |
|
} |
136 |
|
|
137 |
|
/** |
161 |
|
q.add(new Object()); |
162 |
|
q.add(new Object()); |
163 |
|
shouldThrow(); |
164 |
< |
} |
169 |
< |
catch (ClassCastException success) {} |
164 |
> |
} catch (ClassCastException success) {} |
165 |
|
} |
166 |
|
|
167 |
|
|
173 |
|
NavigableSet q = set0(); |
174 |
|
q.addAll(null); |
175 |
|
shouldThrow(); |
176 |
< |
} |
182 |
< |
catch (NullPointerException success) {} |
176 |
> |
} catch (NullPointerException success) {} |
177 |
|
} |
178 |
+ |
|
179 |
|
/** |
180 |
|
* addAll of a collection with null elements throws NPE |
181 |
|
*/ |
185 |
|
Integer[] ints = new Integer[SIZE]; |
186 |
|
q.addAll(Arrays.asList(ints)); |
187 |
|
shouldThrow(); |
188 |
< |
} |
194 |
< |
catch (NullPointerException success) {} |
188 |
> |
} catch (NullPointerException success) {} |
189 |
|
} |
190 |
+ |
|
191 |
|
/** |
192 |
|
* addAll of a collection with any null elements throws NPE after |
193 |
|
* possibly adding some elements |
200 |
|
ints[i] = new Integer(i+SIZE); |
201 |
|
q.addAll(Arrays.asList(ints)); |
202 |
|
shouldThrow(); |
203 |
< |
} |
209 |
< |
catch (NullPointerException success) {} |
203 |
> |
} catch (NullPointerException success) {} |
204 |
|
} |
205 |
|
|
206 |
|
/** |
207 |
|
* Set contains all elements of successful addAll |
208 |
|
*/ |
209 |
|
public void testAddAll5() { |
210 |
< |
try { |
211 |
< |
Integer[] empty = new Integer[0]; |
212 |
< |
Integer[] ints = new Integer[SIZE]; |
213 |
< |
for (int i = 0; i < SIZE; ++i) |
214 |
< |
ints[i] = new Integer(SIZE-1- i); |
215 |
< |
NavigableSet q = set0(); |
216 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
217 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
218 |
< |
for (int i = 0; i < SIZE; ++i) |
225 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
226 |
< |
} |
227 |
< |
finally {} |
210 |
> |
Integer[] empty = new Integer[0]; |
211 |
> |
Integer[] ints = new Integer[SIZE]; |
212 |
> |
for (int i = 0; i < SIZE; ++i) |
213 |
> |
ints[i] = new Integer(SIZE-1- i); |
214 |
> |
NavigableSet q = set0(); |
215 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
216 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
217 |
> |
for (int i = 0; i < SIZE; ++i) |
218 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
219 |
|
} |
220 |
|
|
221 |
|
/** |
224 |
|
public void testPoll() { |
225 |
|
NavigableSet q = populatedSet(SIZE); |
226 |
|
for (int i = 0; i < SIZE; ++i) { |
227 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
227 |
> |
assertEquals(i, q.pollFirst()); |
228 |
|
} |
229 |
< |
assertNull(q.pollFirst()); |
229 |
> |
assertNull(q.pollFirst()); |
230 |
|
} |
231 |
|
|
232 |
|
/** |
235 |
|
public void testRemoveElement() { |
236 |
|
NavigableSet q = populatedSet(SIZE); |
237 |
|
for (int i = 1; i < SIZE; i+=2) { |
238 |
< |
assertTrue(q.remove(new Integer(i))); |
238 |
> |
assertTrue(q.contains(i)); |
239 |
> |
assertTrue(q.remove(i)); |
240 |
> |
assertFalse(q.contains(i)); |
241 |
> |
assertTrue(q.contains(i-1)); |
242 |
|
} |
243 |
|
for (int i = 0; i < SIZE; i+=2) { |
244 |
< |
assertTrue(q.remove(new Integer(i))); |
245 |
< |
assertFalse(q.remove(new Integer(i+1))); |
244 |
> |
assertTrue(q.contains(i)); |
245 |
> |
assertTrue(q.remove(i)); |
246 |
> |
assertFalse(q.contains(i)); |
247 |
> |
assertFalse(q.remove(i+1)); |
248 |
> |
assertFalse(q.contains(i+1)); |
249 |
|
} |
250 |
|
assertTrue(q.isEmpty()); |
251 |
|
} |
270 |
|
q.clear(); |
271 |
|
assertTrue(q.isEmpty()); |
272 |
|
assertEquals(0, q.size()); |
273 |
< |
q.add(new Integer(1)); |
273 |
> |
assertTrue(q.add(new Integer(1))); |
274 |
|
assertFalse(q.isEmpty()); |
275 |
|
q.clear(); |
276 |
|
assertTrue(q.isEmpty()); |
343 |
|
|
344 |
|
Object e4 = q.lower(zero); |
345 |
|
assertNull(e4); |
349 |
– |
|
346 |
|
} |
347 |
|
|
348 |
|
/** |
361 |
|
|
362 |
|
Object e4 = q.higher(six); |
363 |
|
assertNull(e4); |
368 |
– |
|
364 |
|
} |
365 |
|
|
366 |
|
/** |
379 |
|
|
380 |
|
Object e4 = q.floor(zero); |
381 |
|
assertNull(e4); |
387 |
– |
|
382 |
|
} |
383 |
|
|
384 |
|
/** |
397 |
|
|
398 |
|
Object e4 = q.ceiling(six); |
399 |
|
assertNull(e4); |
406 |
– |
|
400 |
|
} |
401 |
|
|
402 |
|
/** |
403 |
< |
* toArray contains all elements |
403 |
> |
* toArray contains all elements in sorted order |
404 |
|
*/ |
405 |
|
public void testToArray() { |
406 |
|
NavigableSet q = populatedSet(SIZE); |
407 |
< |
Object[] o = q.toArray(); |
408 |
< |
Arrays.sort(o); |
409 |
< |
for (int i = 0; i < o.length; i++) |
417 |
< |
assertEquals(o[i], q.pollFirst()); |
407 |
> |
Object[] o = q.toArray(); |
408 |
> |
for (int i = 0; i < o.length; i++) |
409 |
> |
assertSame(o[i], q.pollFirst()); |
410 |
|
} |
411 |
|
|
412 |
|
/** |
413 |
< |
* toArray(a) contains all elements |
413 |
> |
* toArray(a) contains all elements in sorted order |
414 |
|
*/ |
415 |
|
public void testToArray2() { |
416 |
< |
NavigableSet q = populatedSet(SIZE); |
417 |
< |
Integer[] ints = new Integer[SIZE]; |
418 |
< |
ints = (Integer[])q.toArray(ints); |
419 |
< |
Arrays.sort(ints); |
416 |
> |
NavigableSet<Integer> q = populatedSet(SIZE); |
417 |
> |
Integer[] ints = new Integer[SIZE]; |
418 |
> |
Integer[] array = q.toArray(ints); |
419 |
> |
assertSame(ints, array); |
420 |
|
for (int i = 0; i < ints.length; i++) |
421 |
< |
assertEquals(ints[i], q.pollFirst()); |
421 |
> |
assertSame(ints[i], q.pollFirst()); |
422 |
|
} |
423 |
|
|
424 |
|
/** |
427 |
|
public void testIterator() { |
428 |
|
NavigableSet q = populatedSet(SIZE); |
429 |
|
int i = 0; |
430 |
< |
Iterator it = q.iterator(); |
430 |
> |
Iterator it = q.iterator(); |
431 |
|
while (it.hasNext()) { |
432 |
|
assertTrue(q.contains(it.next())); |
433 |
|
++i; |
441 |
|
public void testEmptyIterator() { |
442 |
|
NavigableSet q = set0(); |
443 |
|
int i = 0; |
444 |
< |
Iterator it = q.iterator(); |
444 |
> |
Iterator it = q.iterator(); |
445 |
|
while (it.hasNext()) { |
446 |
|
assertTrue(q.contains(it.next())); |
447 |
|
++i; |
452 |
|
/** |
453 |
|
* iterator.remove removes current element |
454 |
|
*/ |
455 |
< |
public void testIteratorRemove () { |
455 |
> |
public void testIteratorRemove() { |
456 |
|
final NavigableSet q = set0(); |
457 |
|
q.add(new Integer(2)); |
458 |
|
q.add(new Integer(1)); |
463 |
|
it.remove(); |
464 |
|
|
465 |
|
it = q.iterator(); |
466 |
< |
assertEquals(it.next(), new Integer(2)); |
467 |
< |
assertEquals(it.next(), new Integer(3)); |
466 |
> |
assertEquals(it.next(), 2); |
467 |
> |
assertEquals(it.next(), 3); |
468 |
|
assertFalse(it.hasNext()); |
469 |
|
} |
470 |
|
|
483 |
|
/** |
484 |
|
* A deserialized serialized set has same elements |
485 |
|
*/ |
486 |
< |
public void testSerialization() { |
486 |
> |
public void testSerialization() throws Exception { |
487 |
|
NavigableSet q = populatedSet(SIZE); |
488 |
< |
try { |
489 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
490 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
491 |
< |
out.writeObject(q); |
492 |
< |
out.close(); |
493 |
< |
|
494 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
495 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
496 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
497 |
< |
assertEquals(q.size(), r.size()); |
498 |
< |
while (!q.isEmpty()) |
507 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
508 |
< |
} catch (Exception e){ |
509 |
< |
e.printStackTrace(); |
510 |
< |
unexpectedException(); |
511 |
< |
} |
488 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
489 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
490 |
> |
out.writeObject(q); |
491 |
> |
out.close(); |
492 |
> |
|
493 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
494 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
495 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
496 |
> |
assertEquals(q.size(), r.size()); |
497 |
> |
while (!q.isEmpty()) |
498 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
499 |
|
} |
500 |
|
|
501 |
|
/** |
659 |
|
q.add(new Object()); |
660 |
|
q.add(new Object()); |
661 |
|
shouldThrow(); |
662 |
< |
} |
676 |
< |
catch (ClassCastException success) {} |
662 |
> |
} catch (ClassCastException success) {} |
663 |
|
} |
664 |
|
|
665 |
|
|
671 |
|
NavigableSet q = dset0(); |
672 |
|
q.addAll(null); |
673 |
|
shouldThrow(); |
674 |
< |
} |
689 |
< |
catch (NullPointerException success) {} |
674 |
> |
} catch (NullPointerException success) {} |
675 |
|
} |
676 |
+ |
|
677 |
|
/** |
678 |
|
* addAll of a collection with null elements throws NPE |
679 |
|
*/ |
683 |
|
Integer[] ints = new Integer[SIZE]; |
684 |
|
q.addAll(Arrays.asList(ints)); |
685 |
|
shouldThrow(); |
686 |
< |
} |
701 |
< |
catch (NullPointerException success) {} |
686 |
> |
} catch (NullPointerException success) {} |
687 |
|
} |
688 |
+ |
|
689 |
|
/** |
690 |
|
* addAll of a collection with any null elements throws NPE after |
691 |
|
* possibly adding some elements |
698 |
|
ints[i] = new Integer(i+SIZE); |
699 |
|
q.addAll(Arrays.asList(ints)); |
700 |
|
shouldThrow(); |
701 |
< |
} |
716 |
< |
catch (NullPointerException success) {} |
701 |
> |
} catch (NullPointerException success) {} |
702 |
|
} |
703 |
|
|
704 |
|
/** |
705 |
|
* Set contains all elements of successful addAll |
706 |
|
*/ |
707 |
|
public void testDescendingAddAll5() { |
708 |
< |
try { |
709 |
< |
Integer[] empty = new Integer[0]; |
710 |
< |
Integer[] ints = new Integer[SIZE]; |
711 |
< |
for (int i = 0; i < SIZE; ++i) |
712 |
< |
ints[i] = new Integer(SIZE-1- i); |
713 |
< |
NavigableSet q = dset0(); |
714 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
715 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
716 |
< |
for (int i = 0; i < SIZE; ++i) |
732 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
733 |
< |
} |
734 |
< |
finally {} |
708 |
> |
Integer[] empty = new Integer[0]; |
709 |
> |
Integer[] ints = new Integer[SIZE]; |
710 |
> |
for (int i = 0; i < SIZE; ++i) |
711 |
> |
ints[i] = new Integer(SIZE-1- i); |
712 |
> |
NavigableSet q = dset0(); |
713 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
714 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
715 |
> |
for (int i = 0; i < SIZE; ++i) |
716 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
717 |
|
} |
718 |
|
|
719 |
|
/** |
722 |
|
public void testDescendingPoll() { |
723 |
|
NavigableSet q = populatedSet(SIZE); |
724 |
|
for (int i = 0; i < SIZE; ++i) { |
725 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
725 |
> |
assertEquals(i, q.pollFirst()); |
726 |
|
} |
727 |
< |
assertNull(q.pollFirst()); |
727 |
> |
assertNull(q.pollFirst()); |
728 |
|
} |
729 |
|
|
730 |
|
/** |
762 |
|
q.clear(); |
763 |
|
assertTrue(q.isEmpty()); |
764 |
|
assertEquals(0, q.size()); |
765 |
< |
q.add(new Integer(1)); |
765 |
> |
assertTrue(q.add(new Integer(1))); |
766 |
|
assertFalse(q.isEmpty()); |
767 |
|
q.clear(); |
768 |
|
assertTrue(q.isEmpty()); |
835 |
|
|
836 |
|
Object e4 = q.lower(zero); |
837 |
|
assertNull(e4); |
856 |
– |
|
838 |
|
} |
839 |
|
|
840 |
|
/** |
853 |
|
|
854 |
|
Object e4 = q.higher(m6); |
855 |
|
assertNull(e4); |
875 |
– |
|
856 |
|
} |
857 |
|
|
858 |
|
/** |
871 |
|
|
872 |
|
Object e4 = q.floor(zero); |
873 |
|
assertNull(e4); |
894 |
– |
|
874 |
|
} |
875 |
|
|
876 |
|
/** |
889 |
|
|
890 |
|
Object e4 = q.ceiling(m6); |
891 |
|
assertNull(e4); |
913 |
– |
|
892 |
|
} |
893 |
|
|
894 |
|
/** |
896 |
|
*/ |
897 |
|
public void testDescendingToArray() { |
898 |
|
NavigableSet q = populatedSet(SIZE); |
899 |
< |
Object[] o = q.toArray(); |
899 |
> |
Object[] o = q.toArray(); |
900 |
|
Arrays.sort(o); |
901 |
< |
for (int i = 0; i < o.length; i++) |
902 |
< |
assertEquals(o[i], q.pollFirst()); |
901 |
> |
for (int i = 0; i < o.length; i++) |
902 |
> |
assertEquals(o[i], q.pollFirst()); |
903 |
|
} |
904 |
|
|
905 |
|
/** |
907 |
|
*/ |
908 |
|
public void testDescendingToArray2() { |
909 |
|
NavigableSet q = populatedSet(SIZE); |
910 |
< |
Integer[] ints = new Integer[SIZE]; |
911 |
< |
ints = (Integer[])q.toArray(ints); |
910 |
> |
Integer[] ints = new Integer[SIZE]; |
911 |
> |
assertSame(ints, q.toArray(ints)); |
912 |
|
Arrays.sort(ints); |
913 |
|
for (int i = 0; i < ints.length; i++) |
914 |
|
assertEquals(ints[i], q.pollFirst()); |
920 |
|
public void testDescendingIterator() { |
921 |
|
NavigableSet q = populatedSet(SIZE); |
922 |
|
int i = 0; |
923 |
< |
Iterator it = q.iterator(); |
923 |
> |
Iterator it = q.iterator(); |
924 |
|
while (it.hasNext()) { |
925 |
|
assertTrue(q.contains(it.next())); |
926 |
|
++i; |
934 |
|
public void testDescendingEmptyIterator() { |
935 |
|
NavigableSet q = dset0(); |
936 |
|
int i = 0; |
937 |
< |
Iterator it = q.iterator(); |
937 |
> |
Iterator it = q.iterator(); |
938 |
|
while (it.hasNext()) { |
939 |
|
assertTrue(q.contains(it.next())); |
940 |
|
++i; |
945 |
|
/** |
946 |
|
* iterator.remove removes current element |
947 |
|
*/ |
948 |
< |
public void testDescendingIteratorRemove () { |
948 |
> |
public void testDescendingIteratorRemove() { |
949 |
|
final NavigableSet q = dset0(); |
950 |
|
q.add(new Integer(2)); |
951 |
|
q.add(new Integer(1)); |
956 |
|
it.remove(); |
957 |
|
|
958 |
|
it = q.iterator(); |
959 |
< |
assertEquals(it.next(), new Integer(2)); |
960 |
< |
assertEquals(it.next(), new Integer(3)); |
959 |
> |
assertEquals(it.next(), 2); |
960 |
> |
assertEquals(it.next(), 3); |
961 |
|
assertFalse(it.hasNext()); |
962 |
|
} |
963 |
|
|
976 |
|
/** |
977 |
|
* A deserialized serialized set has same elements |
978 |
|
*/ |
979 |
< |
public void testDescendingSerialization() { |
979 |
> |
public void testDescendingSerialization() throws Exception { |
980 |
|
NavigableSet q = populatedSet(SIZE); |
981 |
< |
try { |
982 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
983 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
984 |
< |
out.writeObject(q); |
985 |
< |
out.close(); |
986 |
< |
|
987 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
988 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
989 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
990 |
< |
assertEquals(q.size(), r.size()); |
991 |
< |
while (!q.isEmpty()) |
1014 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
1015 |
< |
} catch (Exception e){ |
1016 |
< |
e.printStackTrace(); |
1017 |
< |
unexpectedException(); |
1018 |
< |
} |
981 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
982 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
983 |
> |
out.writeObject(q); |
984 |
> |
out.close(); |
985 |
> |
|
986 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
987 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
988 |
> |
NavigableSet r = (NavigableSet)in.readObject(); |
989 |
> |
assertEquals(q.size(), r.size()); |
990 |
> |
while (!q.isEmpty()) |
991 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
992 |
|
} |
993 |
|
|
994 |
|
/** |