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 |
|
} |
641 |
|
} |
642 |
|
|
643 |
|
/** |
644 |
< |
* toArray() contains all elements |
644 |
> |
* toArray() contains all elements in FIFO order |
645 |
|
*/ |
646 |
|
public void testToArray() { |
647 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
648 |
|
Object[] o = q.toArray(); |
643 |
– |
Arrays.sort(o); |
649 |
|
for (int i = 0; i < o.length; i++) |
650 |
< |
assertEquals(o[i], q.poll()); |
650 |
> |
assertSame(o[i], q.poll()); |
651 |
|
} |
652 |
|
|
653 |
|
/** |
654 |
< |
* toArray(a) contains all elements |
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 |
< |
ints = (Integer[])q.toArray(ints); |
660 |
< |
Arrays.sort(ints); |
659 |
> |
Integer[] array = q.toArray(ints); |
660 |
> |
assertSame(ints, array); |
661 |
|
for (int i = 0; i < ints.length; i++) |
662 |
< |
assertEquals(ints[i], q.poll()); |
662 |
> |
assertSame(ints[i], q.poll()); |
663 |
|
} |
664 |
|
|
665 |
|
/** |
835 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
836 |
|
String s = q.toString(); |
837 |
|
for (int i = 0; i < SIZE; ++i) { |
838 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
838 |
> |
assertTrue(s.contains(String.valueOf(i))); |
839 |
|
} |
840 |
|
} |
841 |
|
|