21 |
|
|
22 |
|
static class MyReverseComparator implements Comparator { |
23 |
|
public int compare(Object x, Object y) { |
24 |
< |
int i = ((Integer)x).intValue(); |
25 |
< |
int j = ((Integer)y).intValue(); |
26 |
< |
if (i < j) return 1; |
27 |
< |
if (i > j) return -1; |
28 |
< |
return 0; |
24 |
> |
return ((Comparable)y).compareTo(x); |
25 |
|
} |
26 |
|
} |
27 |
|
|
260 |
|
public void testPoll() { |
261 |
|
PriorityQueue q = populatedQueue(SIZE); |
262 |
|
for (int i = 0; i < SIZE; ++i) { |
263 |
< |
assertEquals(i, ((Integer)q.poll()).intValue()); |
263 |
> |
assertEquals(i, q.poll()); |
264 |
|
} |
265 |
|
assertNull(q.poll()); |
266 |
|
} |
271 |
|
public void testPeek() { |
272 |
|
PriorityQueue q = populatedQueue(SIZE); |
273 |
|
for (int i = 0; i < SIZE; ++i) { |
274 |
< |
assertEquals(i, ((Integer)q.peek()).intValue()); |
275 |
< |
q.poll(); |
274 |
> |
assertEquals(i, q.peek()); |
275 |
> |
assertEquals(i, q.poll()); |
276 |
|
assertTrue(q.peek() == null || |
277 |
< |
i != ((Integer)q.peek()).intValue()); |
277 |
> |
!q.peek().equals(i)); |
278 |
|
} |
279 |
|
assertNull(q.peek()); |
280 |
|
} |
285 |
|
public void testElement() { |
286 |
|
PriorityQueue q = populatedQueue(SIZE); |
287 |
|
for (int i = 0; i < SIZE; ++i) { |
288 |
< |
assertEquals(i, ((Integer)q.element()).intValue()); |
289 |
< |
q.poll(); |
288 |
> |
assertEquals(i, q.element()); |
289 |
> |
assertEquals(i, q.poll()); |
290 |
|
} |
291 |
|
try { |
292 |
|
q.element(); |
300 |
|
public void testRemove() { |
301 |
|
PriorityQueue q = populatedQueue(SIZE); |
302 |
|
for (int i = 0; i < SIZE; ++i) { |
303 |
< |
assertEquals(i, ((Integer)q.remove()).intValue()); |
303 |
> |
assertEquals(i, q.remove()); |
304 |
|
} |
305 |
|
try { |
306 |
|
q.remove(); |