461 |
|
} |
462 |
|
|
463 |
|
/** |
464 |
+ |
* Identity-based version for use in Itr.remove |
465 |
+ |
*/ |
466 |
+ |
void removeEQ(Object o) { |
467 |
+ |
final ReentrantLock lock = this.lock; |
468 |
+ |
lock.lock(); |
469 |
+ |
try { |
470 |
+ |
for (Iterator<E> it = q.iterator(); it.hasNext(); ) { |
471 |
+ |
if (o == it.next()) { |
472 |
+ |
it.remove(); |
473 |
+ |
break; |
474 |
+ |
} |
475 |
+ |
} |
476 |
+ |
} finally { |
477 |
+ |
lock.unlock(); |
478 |
+ |
} |
479 |
+ |
} |
480 |
+ |
|
481 |
+ |
/** |
482 |
|
* Returns an iterator over all the elements (both expired and |
483 |
|
* unexpired) in this queue. The iterator does not return the |
484 |
|
* elements in any particular order. |
501 |
|
*/ |
502 |
|
private class Itr implements Iterator<E> { |
503 |
|
final Object[] array; // Array of all elements |
504 |
< |
int cursor; // index of next element to return; |
504 |
> |
int cursor; // index of next element to return |
505 |
|
int lastRet; // index of last element, or -1 if no such |
506 |
|
|
507 |
|
Itr(Object[] array) { |
524 |
|
public void remove() { |
525 |
|
if (lastRet < 0) |
526 |
|
throw new IllegalStateException(); |
527 |
< |
Object x = array[lastRet]; |
527 |
> |
removeEQ(array[lastRet]); |
528 |
|
lastRet = -1; |
511 |
– |
// Traverse underlying queue to find == element, |
512 |
– |
// not just a .equals element. |
513 |
– |
lock.lock(); |
514 |
– |
try { |
515 |
– |
for (Iterator<E> it = q.iterator(); it.hasNext(); ) { |
516 |
– |
if (it.next() == x) { |
517 |
– |
it.remove(); |
518 |
– |
return; |
519 |
– |
} |
520 |
– |
} |
521 |
– |
} finally { |
522 |
– |
lock.unlock(); |
523 |
– |
} |
529 |
|
} |
530 |
|
} |
531 |
|
|