4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.Arrays; |
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
> |
|
9 |
|
import java.util.ArrayList; |
10 |
+ |
import java.util.Arrays; |
11 |
|
import java.util.Collection; |
12 |
|
import java.util.Deque; |
13 |
|
import java.util.Iterator; |
19 |
|
import java.util.concurrent.Executors; |
20 |
|
import java.util.concurrent.ExecutorService; |
21 |
|
import java.util.concurrent.LinkedBlockingDeque; |
22 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
> |
|
23 |
> |
import junit.framework.Test; |
24 |
|
|
25 |
|
public class LinkedBlockingDequeTest extends JSR166TestCase { |
26 |
|
|
276 |
|
*/ |
277 |
|
public void testRemoveFirstOccurrence() { |
278 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
279 |
< |
for (int i = 1; i < SIZE; i+=2) { |
279 |
> |
for (int i = 1; i < SIZE; i += 2) { |
280 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
281 |
|
} |
282 |
< |
for (int i = 0; i < SIZE; i+=2) { |
282 |
> |
for (int i = 0; i < SIZE; i += 2) { |
283 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
284 |
|
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
285 |
|
} |
291 |
|
*/ |
292 |
|
public void testRemoveLastOccurrence() { |
293 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
294 |
< |
for (int i = 1; i < SIZE; i+=2) { |
294 |
> |
for (int i = 1; i < SIZE; i += 2) { |
295 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
296 |
|
} |
297 |
< |
for (int i = 0; i < SIZE; i+=2) { |
297 |
> |
for (int i = 0; i < SIZE; i += 2) { |
298 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
299 |
|
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
300 |
|
} |
438 |
|
try { |
439 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
440 |
|
for (int i = 0; i < SIZE; ++i) { |
441 |
< |
Integer I = new Integer(i); |
442 |
< |
q.push(I); |
443 |
< |
assertEquals(I, q.peek()); |
441 |
> |
Integer x = new Integer(i); |
442 |
> |
q.push(x); |
443 |
> |
assertEquals(x, q.peek()); |
444 |
|
} |
445 |
|
assertEquals(0, q.remainingCapacity()); |
446 |
|
q.push(new Integer(SIZE)); |
558 |
|
public void testPut() throws InterruptedException { |
559 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
560 |
|
for (int i = 0; i < SIZE; ++i) { |
561 |
< |
Integer I = new Integer(i); |
562 |
< |
q.put(I); |
563 |
< |
assertTrue(q.contains(I)); |
561 |
> |
Integer x = new Integer(i); |
562 |
> |
q.put(x); |
563 |
> |
assertTrue(q.contains(x)); |
564 |
|
} |
565 |
|
assertEquals(0, q.remainingCapacity()); |
566 |
|
} |
790 |
|
public void testPutFirst() throws InterruptedException { |
791 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
792 |
|
for (int i = 0; i < SIZE; ++i) { |
793 |
< |
Integer I = new Integer(i); |
794 |
< |
q.putFirst(I); |
795 |
< |
assertTrue(q.contains(I)); |
793 |
> |
Integer x = new Integer(i); |
794 |
> |
q.putFirst(x); |
795 |
> |
assertTrue(q.contains(x)); |
796 |
|
} |
797 |
|
assertEquals(0, q.remainingCapacity()); |
798 |
|
} |
1137 |
|
public void testPutLast() throws InterruptedException { |
1138 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1139 |
|
for (int i = 0; i < SIZE; ++i) { |
1140 |
< |
Integer I = new Integer(i); |
1141 |
< |
q.putLast(I); |
1142 |
< |
assertTrue(q.contains(I)); |
1140 |
> |
Integer x = new Integer(i); |
1141 |
> |
q.putLast(x); |
1142 |
> |
assertTrue(q.contains(x)); |
1143 |
|
} |
1144 |
|
assertEquals(0, q.remainingCapacity()); |
1145 |
|
} |
1473 |
|
assertTrue(q.removeAll(p)); |
1474 |
|
assertEquals(SIZE-i, q.size()); |
1475 |
|
for (int j = 0; j < i; ++j) { |
1476 |
< |
Integer I = (Integer)(p.remove()); |
1477 |
< |
assertFalse(q.contains(I)); |
1476 |
> |
Integer x = (Integer)(p.remove()); |
1477 |
> |
assertFalse(q.contains(x)); |
1478 |
|
} |
1479 |
|
} |
1480 |
|
} |
1773 |
|
assertEquals(SIZE-k, q.size()); |
1774 |
|
for (int j = 0; j < k; ++j) |
1775 |
|
assertEquals(l.get(j), new Integer(j)); |
1776 |
< |
while (q.poll() != null) ; |
1776 |
> |
do {} while (q.poll() != null); |
1777 |
|
} |
1778 |
|
} |
1779 |
|
|