47 |
|
new InitialCapacity().testSuite()); |
48 |
|
} |
49 |
|
|
50 |
– |
private static final int NOCAP = Integer.MAX_VALUE; |
51 |
– |
|
50 |
|
/** Sample Comparator */ |
51 |
|
static class MyReverseComparator implements Comparator { |
52 |
|
public int compare(Object x, Object y) { |
62 |
|
PriorityBlockingQueue<Integer> q = |
63 |
|
new PriorityBlockingQueue<Integer>(n); |
64 |
|
assertTrue(q.isEmpty()); |
65 |
< |
for (int i = n-1; i >= 0; i-=2) |
65 |
> |
for (int i = n-1; i >= 0; i -= 2) |
66 |
|
assertTrue(q.offer(new Integer(i))); |
67 |
< |
for (int i = (n & 1); i < n; i+=2) |
67 |
> |
for (int i = (n & 1); i < n; i += 2) |
68 |
|
assertTrue(q.offer(new Integer(i))); |
69 |
|
assertFalse(q.isEmpty()); |
70 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
70 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
71 |
|
assertEquals(n, q.size()); |
72 |
|
return q; |
73 |
|
} |
76 |
|
* A new queue has unbounded capacity |
77 |
|
*/ |
78 |
|
public void testConstructor1() { |
79 |
< |
assertEquals(NOCAP, new PriorityBlockingQueue(SIZE).remainingCapacity()); |
79 |
> |
assertEquals(Integer.MAX_VALUE, |
80 |
> |
new PriorityBlockingQueue(SIZE).remainingCapacity()); |
81 |
|
} |
82 |
|
|
83 |
|
/** |
158 |
|
public void testEmpty() { |
159 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
160 |
|
assertTrue(q.isEmpty()); |
161 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
161 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
162 |
|
q.add(one); |
163 |
|
assertFalse(q.isEmpty()); |
164 |
|
q.add(two); |
168 |
|
} |
169 |
|
|
170 |
|
/** |
171 |
< |
* remainingCapacity does not change when elements added or removed, |
173 |
< |
* but size does |
171 |
> |
* remainingCapacity() always returns Integer.MAX_VALUE |
172 |
|
*/ |
173 |
|
public void testRemainingCapacity() { |
174 |
< |
PriorityBlockingQueue q = populatedQueue(SIZE); |
174 |
> |
BlockingQueue q = populatedQueue(SIZE); |
175 |
|
for (int i = 0; i < SIZE; ++i) { |
176 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
177 |
< |
assertEquals(SIZE-i, q.size()); |
178 |
< |
q.remove(); |
176 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
177 |
> |
assertEquals(SIZE - i, q.size()); |
178 |
> |
assertEquals(i, q.remove()); |
179 |
|
} |
180 |
|
for (int i = 0; i < SIZE; ++i) { |
181 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
181 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
182 |
|
assertEquals(i, q.size()); |
183 |
< |
q.add(new Integer(i)); |
183 |
> |
assertTrue(q.add(i)); |
184 |
|
} |
185 |
|
} |
186 |
|
|
264 |
|
public void testPut() { |
265 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
266 |
|
for (int i = 0; i < SIZE; ++i) { |
267 |
< |
Integer I = new Integer(i); |
268 |
< |
q.put(I); |
269 |
< |
assertTrue(q.contains(I)); |
267 |
> |
Integer x = new Integer(i); |
268 |
> |
q.put(x); |
269 |
> |
assertTrue(q.contains(x)); |
270 |
|
} |
271 |
|
assertEquals(SIZE, q.size()); |
272 |
|
} |
528 |
|
assertTrue(q.removeAll(p)); |
529 |
|
assertEquals(SIZE-i, q.size()); |
530 |
|
for (int j = 0; j < i; ++j) { |
531 |
< |
Integer I = (Integer)(p.remove()); |
532 |
< |
assertFalse(q.contains(I)); |
531 |
> |
Integer x = (Integer)(p.remove()); |
532 |
> |
assertFalse(q.contains(x)); |
533 |
|
} |
534 |
|
} |
535 |
|
} |
574 |
|
*/ |
575 |
|
public void testIterator() { |
576 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
579 |
– |
int i = 0; |
577 |
|
Iterator it = q.iterator(); |
578 |
< |
while (it.hasNext()) { |
578 |
> |
int i; |
579 |
> |
for (i = 0; it.hasNext(); i++) |
580 |
|
assertTrue(q.contains(it.next())); |
583 |
– |
++i; |
584 |
– |
} |
581 |
|
assertEquals(i, SIZE); |
582 |
+ |
assertIteratorExhausted(it); |
583 |
+ |
} |
584 |
+ |
|
585 |
+ |
/** |
586 |
+ |
* iterator of empty collection has no elements |
587 |
+ |
*/ |
588 |
+ |
public void testEmptyIterator() { |
589 |
+ |
assertIteratorExhausted(new PriorityBlockingQueue().iterator()); |
590 |
|
} |
591 |
|
|
592 |
|
/** |