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 deque of given size containing consecutive |
26 |
|
* Integers 0 ... n. |
27 |
|
*/ |
28 |
< |
private ConcurrentLinkedDeque populatedDeque(int n) { |
29 |
< |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
28 |
> |
private ConcurrentLinkedDeque<Integer> populatedDeque(int n) { |
29 |
> |
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<Integer>(); |
30 |
|
assertTrue(q.isEmpty()); |
31 |
|
for (int i = 0; i < n; ++i) |
32 |
|
assertTrue(q.offer(new Integer(i))); |
431 |
|
public void testRemoveElement() { |
432 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
433 |
|
for (int i = 1; i < SIZE; i+=2) { |
434 |
< |
assertTrue(q.remove(new Integer(i))); |
434 |
> |
assertTrue(q.contains(i)); |
435 |
> |
assertTrue(q.remove(i)); |
436 |
> |
assertFalse(q.contains(i)); |
437 |
> |
assertTrue(q.contains(i-1)); |
438 |
|
} |
439 |
|
for (int i = 0; i < SIZE; i+=2) { |
440 |
< |
assertTrue(q.remove(new Integer(i))); |
441 |
< |
assertFalse(q.remove(new Integer(i+1))); |
440 |
> |
assertTrue(q.contains(i)); |
441 |
> |
assertTrue(q.remove(i)); |
442 |
> |
assertFalse(q.contains(i)); |
443 |
> |
assertFalse(q.remove(i+1)); |
444 |
> |
assertFalse(q.contains(i+1)); |
445 |
|
} |
446 |
|
assertTrue(q.isEmpty()); |
447 |
|
} |
654 |
|
* toArray(a) contains all elements in FIFO order |
655 |
|
*/ |
656 |
|
public void testToArray2() { |
657 |
< |
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
657 |
> |
ConcurrentLinkedDeque<Integer> q = populatedDeque(SIZE); |
658 |
|
Integer[] ints = new Integer[SIZE]; |
659 |
< |
assertSame(ints, q.toArray(ints)); |
659 |
> |
Integer[] array = q.toArray(ints); |
660 |
> |
assertSame(ints, array); |
661 |
|
for (int i = 0; i < ints.length; i++) |
662 |
|
assertSame(ints[i], q.poll()); |
663 |
|
} |