465 } 466 } 467 468 /** 469 * Removes a single instance of the specified element from this 470 * queue, if it is present, whether or not it has expired. 471 */ 472 public boolean remove(Object o) { 473 final ReentrantLock lock = this.lock; 474 lock.lock(); 475 try { 476 return q.remove(o); 477 } finally { 478 lock.unlock(); 479 } 480 } 481 482 /** 483 * Returns an iterator over all the elements (both expired and 484 * unexpired) in this queue. The iterator does not return the 485 * elements in any particular order. The returned 486 * <tt>Iterator</tt> is a "weakly consistent" iterator that will 487 * never throw {@link ConcurrentModificationException}, and 488 * guarantees to traverse elements as they existed upon 489 * construction of the iterator, and may (but is not guaranteed 490 * to) reflect any modifications subsequent to construction. 491 * 492 * @return an iterator over the elements in this queue 493 */ 494 public Iterator<E> iterator() { 495 return new Itr(toArray()); 496 } 497 498 /** 499 * Snapshot iterator that works off copy of underlying q array. 500 */ 501 private class Itr implements Iterator<E> { 502 final Object[] array; // Array of all elements 503 int cursor; // index of next element to return; 504 int lastRet; // index of last element, or -1 if no such 505 506 Itr(Object[] array) { 507 lastRet = -1; 508 this.array = array; 509 } 510 511 public boolean hasNext() { | 465 } 466 } 467 468 /** 469 * Removes a single instance of the specified element from this 470 * queue, if it is present, whether or not it has expired. 471 */ 472 public boolean remove(Object o) { 473 final ReentrantLock lock = this.lock; 474 lock.lock(); 475 try { 476 return q.remove(o); 477 } finally { 478 lock.unlock(); 479 } 480 } 481 482 /** 483 * Returns an iterator over all the elements (both expired and 484 * unexpired) in this queue. The iterator does not return the 485 * elements in any particular order. 486 * 487 * <p>The returned iterator is a "weakly consistent" iterator that 488 * will never throw {@link java.util.ConcurrentModificationException 489 * ConcurrentModificationException}, and guarantees to traverse 490 * elements as they existed upon construction of the iterator, and 491 * may (but is not guaranteed to) reflect any modifications 492 * subsequent to construction. 493 * 494 * @return an iterator over the elements in this queue 495 */ 496 public Iterator<E> iterator() { 497 return new Itr(toArray()); 498 } 499 500 /** 501 * Snapshot iterator that works off copy of underlying q array. 502 */ 503 private class Itr implements Iterator<E> { 504 final Object[] array; // Array of all elements 505 int cursor; // index of next element to return; 506 int lastRet; // index of last element, or -1 if no such 507 508 Itr(Object[] array) { 509 lastRet = -1; 510 this.array = array; 511 } 512 513 public boolean hasNext() { |