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 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
29 |
|
* Create a queue of given size containing consecutive |
30 |
|
* Integers 0 ... n. |
31 |
|
*/ |
32 |
< |
private PriorityQueue populatedQueue(int n) { |
33 |
< |
PriorityQueue q = new PriorityQueue(n); |
32 |
> |
private PriorityQueue<Integer> populatedQueue(int n) { |
33 |
> |
PriorityQueue<Integer> q = new PriorityQueue<Integer>(n); |
34 |
|
assertTrue(q.isEmpty()); |
35 |
|
for (int i = n-1; i >= 0; i-=2) |
36 |
|
assertTrue(q.offer(new Integer(i))); |
316 |
|
public void testRemoveElement() { |
317 |
|
PriorityQueue q = populatedQueue(SIZE); |
318 |
|
for (int i = 1; i < SIZE; i+=2) { |
319 |
< |
assertTrue(q.remove(new Integer(i))); |
319 |
> |
assertTrue(q.contains(i)); |
320 |
> |
assertTrue(q.remove(i)); |
321 |
> |
assertFalse(q.contains(i)); |
322 |
> |
assertTrue(q.contains(i-1)); |
323 |
|
} |
324 |
|
for (int i = 0; i < SIZE; i+=2) { |
325 |
< |
assertTrue(q.remove(new Integer(i))); |
326 |
< |
assertFalse(q.remove(new Integer(i+1))); |
325 |
> |
assertTrue(q.contains(i)); |
326 |
> |
assertTrue(q.remove(i)); |
327 |
> |
assertFalse(q.contains(i)); |
328 |
> |
assertFalse(q.remove(i+1)); |
329 |
> |
assertFalse(q.contains(i+1)); |
330 |
|
} |
331 |
|
assertTrue(q.isEmpty()); |
332 |
|
} |
421 |
|
* toArray(a) contains all elements |
422 |
|
*/ |
423 |
|
public void testToArray2() { |
424 |
< |
PriorityQueue q = populatedQueue(SIZE); |
424 |
> |
PriorityQueue<Integer> q = populatedQueue(SIZE); |
425 |
|
Integer[] ints = new Integer[SIZE]; |
426 |
< |
assertSame(ints, q.toArray(ints)); |
426 |
> |
Integer[] array = q.toArray(ints); |
427 |
> |
assertSame(ints, array); |
428 |
|
Arrays.sort(ints); |
429 |
|
for (int i = 0; i < ints.length; i++) |
430 |
|
assertSame(ints[i], q.poll()); |
463 |
|
assertFalse(it.hasNext()); |
464 |
|
} |
465 |
|
|
459 |
– |
|
466 |
|
/** |
467 |
|
* toString contains toStrings of elements |
468 |
|
*/ |
470 |
|
PriorityQueue q = populatedQueue(SIZE); |
471 |
|
String s = q.toString(); |
472 |
|
for (int i = 0; i < SIZE; ++i) { |
473 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
473 |
> |
assertTrue(s.contains(String.valueOf(i))); |
474 |
|
} |
475 |
|
} |
476 |
|
|