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 |
|
|
111 |
|
* The comparator used in constructor is used |
112 |
|
*/ |
113 |
|
public void testConstructor7() { |
114 |
< |
try { |
115 |
< |
MyReverseComparator cmp = new MyReverseComparator(); |
116 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); |
117 |
< |
assertEquals(cmp, q.comparator()); |
118 |
< |
Integer[] ints = new Integer[SIZE]; |
119 |
< |
for (int i = 0; i < SIZE; ++i) |
120 |
< |
ints[i] = new Integer(i); |
121 |
< |
q.addAll(Arrays.asList(ints)); |
122 |
< |
for (int i = SIZE-1; i >= 0; --i) |
127 |
< |
assertEquals(ints[i], q.pollFirst()); |
128 |
< |
} |
129 |
< |
finally {} |
114 |
> |
MyReverseComparator cmp = new MyReverseComparator(); |
115 |
> |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); |
116 |
> |
assertEquals(cmp, q.comparator()); |
117 |
> |
Integer[] ints = new Integer[SIZE]; |
118 |
> |
for (int i = 0; i < SIZE; ++i) |
119 |
> |
ints[i] = new Integer(i); |
120 |
> |
q.addAll(Arrays.asList(ints)); |
121 |
> |
for (int i = SIZE-1; i >= 0; --i) |
122 |
> |
assertEquals(ints[i], q.pollFirst()); |
123 |
|
} |
124 |
|
|
125 |
|
/** |
233 |
|
* Set contains all elements of successful addAll |
234 |
|
*/ |
235 |
|
public void testAddAll5() { |
236 |
< |
try { |
237 |
< |
Integer[] empty = new Integer[0]; |
238 |
< |
Integer[] ints = new Integer[SIZE]; |
239 |
< |
for (int i = 0; i < SIZE; ++i) |
240 |
< |
ints[i] = new Integer(SIZE-1-i); |
241 |
< |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
242 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
243 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
244 |
< |
for (int i = 0; i < SIZE; ++i) |
252 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
253 |
< |
} |
254 |
< |
finally {} |
236 |
> |
Integer[] empty = new Integer[0]; |
237 |
> |
Integer[] ints = new Integer[SIZE]; |
238 |
> |
for (int i = 0; i < SIZE; ++i) |
239 |
> |
ints[i] = new Integer(SIZE-1-i); |
240 |
> |
ConcurrentSkipListSet q = new ConcurrentSkipListSet(); |
241 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
242 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
243 |
> |
for (int i = 0; i < SIZE; ++i) |
244 |
> |
assertEquals(i, q.pollFirst()); |
245 |
|
} |
246 |
|
|
247 |
|
/** |
250 |
|
public void testPollFirst() { |
251 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
252 |
|
for (int i = 0; i < SIZE; ++i) { |
253 |
< |
assertEquals(i, ((Integer)q.pollFirst()).intValue()); |
253 |
> |
assertEquals(i, q.pollFirst()); |
254 |
|
} |
255 |
|
assertNull(q.pollFirst()); |
256 |
|
} |
261 |
|
public void testPollLast() { |
262 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
263 |
|
for (int i = SIZE-1; i >= 0; --i) { |
264 |
< |
assertEquals(i, ((Integer)q.pollLast()).intValue()); |
264 |
> |
assertEquals(i, q.pollLast()); |
265 |
|
} |
266 |
|
assertNull(q.pollFirst()); |
267 |
|
} |
660 |
|
/** |
661 |
|
* Subsets of subsets subdivide correctly |
662 |
|
*/ |
663 |
< |
public void testRecursiveSubSets() { |
663 |
> |
public void testRecursiveSubSets() throws Exception { |
664 |
|
int setSize = 1000; |
665 |
|
Class cl = ConcurrentSkipListSet.class; |
666 |
|
|
679 |
|
0, setSize - 1, true); |
680 |
|
} |
681 |
|
|
682 |
< |
static NavigableSet<Integer> newSet(Class cl) { |
683 |
< |
NavigableSet<Integer> result = null; |
694 |
< |
try { |
695 |
< |
result = (NavigableSet<Integer>) cl.newInstance(); |
696 |
< |
} catch (Exception e) { |
697 |
< |
fail(); |
698 |
< |
} |
682 |
> |
static NavigableSet<Integer> newSet(Class cl) throws Exception { |
683 |
> |
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance(); |
684 |
|
assertEquals(result.size(), 0); |
685 |
|
assertFalse(result.iterator().hasNext()); |
686 |
|
return result; |
743 |
|
} else { |
744 |
|
try { |
745 |
|
set.add(element); |
746 |
< |
fail(); |
747 |
< |
} catch (IllegalArgumentException e) { |
763 |
< |
// expected |
764 |
< |
} |
746 |
> |
shouldThrow(); |
747 |
> |
} catch (IllegalArgumentException success) {} |
748 |
|
} |
749 |
|
} |
750 |
|
} |
943 |
|
assertEq(rs.last(), -1); |
944 |
|
try { |
945 |
|
set.first(); |
946 |
< |
fail(); |
947 |
< |
} catch (NoSuchElementException e) { |
965 |
< |
// expected |
966 |
< |
} |
946 |
> |
shouldThrow(); |
947 |
> |
} catch (NoSuchElementException success) {} |
948 |
|
try { |
949 |
|
set.last(); |
950 |
< |
fail(); |
951 |
< |
} catch (NoSuchElementException e) { |
971 |
< |
// expected |
972 |
< |
} |
950 |
> |
shouldThrow(); |
951 |
> |
} catch (NoSuchElementException success) {} |
952 |
|
} |
953 |
|
} |
954 |
|
|