5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import java.io.*; |
8 |
> |
import java.util.Arrays; |
9 |
> |
import java.util.Comparator; |
10 |
> |
import java.util.Iterator; |
11 |
> |
import java.util.NavigableSet; |
12 |
> |
import java.util.SortedSet; |
13 |
> |
import java.util.concurrent.ConcurrentSkipListSet; |
14 |
|
|
15 |
|
public class ConcurrentSkipListSubSetTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
27 |
|
} |
28 |
|
|
29 |
|
/** |
30 |
< |
* Create a set of given size containing consecutive |
30 |
> |
* Returns a new set of given size containing consecutive |
31 |
|
* Integers 0 ... n. |
32 |
|
*/ |
33 |
|
private NavigableSet<Integer> populatedSet(int n) { |
48 |
|
} |
49 |
|
|
50 |
|
/** |
51 |
< |
* Create set of first 5 ints |
51 |
> |
* Returns a new set of first 5 ints. |
52 |
|
*/ |
53 |
|
private NavigableSet set5() { |
54 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
66 |
|
} |
67 |
|
|
68 |
|
/** |
69 |
< |
* Create set of first 5 negative ints |
69 |
> |
* Returns a new set of first 5 negative ints. |
70 |
|
*/ |
71 |
|
private NavigableSet dset5() { |
72 |
|
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
449 |
|
assertTrue(q.contains(it.next())); |
450 |
|
++i; |
451 |
|
} |
452 |
< |
assertEquals(i, 0); |
452 |
> |
assertEquals(0, i); |
453 |
|
} |
454 |
|
|
455 |
|
/** |
486 |
|
* A deserialized serialized set has same elements |
487 |
|
*/ |
488 |
|
public void testSerialization() throws Exception { |
489 |
< |
NavigableSet q = populatedSet(SIZE); |
490 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
491 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
492 |
< |
out.writeObject(q); |
493 |
< |
out.close(); |
494 |
< |
|
495 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
496 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
497 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
498 |
< |
assertEquals(q.size(), r.size()); |
499 |
< |
while (!q.isEmpty()) |
500 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
489 |
> |
NavigableSet x = populatedSet(SIZE); |
490 |
> |
NavigableSet y = serialClone(x); |
491 |
> |
|
492 |
> |
assertNotSame(y, x); |
493 |
> |
assertEquals(x.size(), y.size()); |
494 |
> |
assertEquals(x, y); |
495 |
> |
assertEquals(y, x); |
496 |
> |
while (!x.isEmpty()) { |
497 |
> |
assertFalse(y.isEmpty()); |
498 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
499 |
> |
} |
500 |
> |
assertTrue(y.isEmpty()); |
501 |
|
} |
502 |
|
|
503 |
|
/** |
949 |
|
assertTrue(q.contains(it.next())); |
950 |
|
++i; |
951 |
|
} |
952 |
< |
assertEquals(i, 0); |
952 |
> |
assertEquals(0, i); |
953 |
|
} |
954 |
|
|
955 |
|
/** |
986 |
|
* A deserialized serialized set has same elements |
987 |
|
*/ |
988 |
|
public void testDescendingSerialization() throws Exception { |
989 |
< |
NavigableSet q = populatedSet(SIZE); |
990 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
991 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
992 |
< |
out.writeObject(q); |
993 |
< |
out.close(); |
994 |
< |
|
995 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
996 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
997 |
< |
NavigableSet r = (NavigableSet)in.readObject(); |
998 |
< |
assertEquals(q.size(), r.size()); |
999 |
< |
while (!q.isEmpty()) |
1000 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
989 |
> |
NavigableSet x = dset5(); |
990 |
> |
NavigableSet y = serialClone(x); |
991 |
> |
|
992 |
> |
assertNotSame(y, x); |
993 |
> |
assertEquals(x.size(), y.size()); |
994 |
> |
assertEquals(x, y); |
995 |
> |
assertEquals(y, x); |
996 |
> |
while (!x.isEmpty()) { |
997 |
> |
assertFalse(y.isEmpty()); |
998 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
999 |
> |
} |
1000 |
> |
assertTrue(y.isEmpty()); |
1001 |
|
} |
1002 |
|
|
1003 |
|
/** |