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 |
|
*/ |
25 |
|
* Create a queue of given size containing consecutive |
26 |
|
* Integers 0 ... n. |
27 |
|
*/ |
28 |
< |
private ConcurrentLinkedQueue populatedQueue(int n) { |
29 |
< |
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
28 |
> |
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) { |
29 |
> |
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<Integer>(); |
30 |
|
assertTrue(q.isEmpty()); |
31 |
|
for (int i = 0; i < n; ++i) |
32 |
|
assertTrue(q.offer(new Integer(i))); |
284 |
|
public void testRemoveElement() { |
285 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
286 |
|
for (int i = 1; i < SIZE; i+=2) { |
287 |
< |
assertTrue(q.remove(new Integer(i))); |
287 |
> |
assertTrue(q.contains(i)); |
288 |
> |
assertTrue(q.remove(i)); |
289 |
> |
assertFalse(q.contains(i)); |
290 |
> |
assertTrue(q.contains(i-1)); |
291 |
|
} |
292 |
|
for (int i = 0; i < SIZE; i+=2) { |
293 |
< |
assertTrue(q.remove(new Integer(i))); |
294 |
< |
assertFalse(q.remove(new Integer(i+1))); |
293 |
> |
assertTrue(q.contains(i)); |
294 |
> |
assertTrue(q.remove(i)); |
295 |
> |
assertFalse(q.contains(i)); |
296 |
> |
assertFalse(q.remove(i+1)); |
297 |
> |
assertFalse(q.contains(i+1)); |
298 |
|
} |
299 |
|
assertTrue(q.isEmpty()); |
300 |
|
} |
375 |
|
} |
376 |
|
|
377 |
|
/** |
378 |
< |
* toArray contains all elements |
378 |
> |
* toArray contains all elements in FIFO order |
379 |
|
*/ |
380 |
|
public void testToArray() { |
381 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
382 |
|
Object[] o = q.toArray(); |
377 |
– |
Arrays.sort(o); |
383 |
|
for (int i = 0; i < o.length; i++) |
384 |
< |
assertEquals(o[i], q.poll()); |
384 |
> |
assertSame(o[i], q.poll()); |
385 |
|
} |
386 |
|
|
387 |
|
/** |
388 |
< |
* toArray(a) contains all elements |
388 |
> |
* toArray(a) contains all elements in FIFO order |
389 |
|
*/ |
390 |
|
public void testToArray2() { |
391 |
< |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
391 |
> |
ConcurrentLinkedQueue<Integer> q = populatedQueue(SIZE); |
392 |
|
Integer[] ints = new Integer[SIZE]; |
393 |
< |
ints = (Integer[])q.toArray(ints); |
394 |
< |
Arrays.sort(ints); |
393 |
> |
Integer[] array = q.toArray(ints); |
394 |
> |
assertSame(ints, array); |
395 |
|
for (int i = 0; i < ints.length; i++) |
396 |
< |
assertEquals(ints[i], q.poll()); |
396 |
> |
assertSame(ints[i], q.poll()); |
397 |
|
} |
398 |
|
|
399 |
|
/** |