614 |
|
* @return {@code true} if this queue changed as a result of the call |
615 |
|
*/ |
616 |
|
public boolean remove(Object o) { |
617 |
– |
boolean removed = false; |
617 |
|
final ReentrantLock lock = this.lock; |
618 |
|
lock.lock(); |
619 |
|
try { |
620 |
|
int i = indexOf(o); |
621 |
< |
if (i != -1) { |
622 |
< |
removeAt(i); |
623 |
< |
removed = true; |
624 |
< |
} |
621 |
> |
if (i == -1) |
622 |
> |
return false; |
623 |
> |
removeAt(i); |
624 |
> |
return true; |
625 |
|
} finally { |
626 |
|
lock.unlock(); |
627 |
|
} |
629 |
– |
return removed; |
628 |
|
} |
629 |
|
|
632 |
– |
|
630 |
|
/** |
631 |
|
* Identity-based version for use in Itr.remove |
632 |
|
*/ |
635 |
|
lock.lock(); |
636 |
|
try { |
637 |
|
Object[] array = queue; |
638 |
< |
int n = size; |
642 |
< |
for (int i = 0; i < n; i++) { |
638 |
> |
for (int i = 0, n = size; i < n; i++) { |
639 |
|
if (o == array[i]) { |
640 |
|
removeAt(i); |
641 |
|
break; |
655 |
|
* @return {@code true} if this queue contains the specified element |
656 |
|
*/ |
657 |
|
public boolean contains(Object o) { |
662 |
– |
int index; |
658 |
|
final ReentrantLock lock = this.lock; |
659 |
|
lock.lock(); |
660 |
|
try { |
661 |
< |
index = indexOf(o); |
661 |
> |
return indexOf(o) != -1; |
662 |
|
} finally { |
663 |
|
lock.unlock(); |
664 |
|
} |
670 |
– |
return index != -1; |
665 |
|
} |
666 |
|
|
667 |
|
/** |
687 |
|
} |
688 |
|
} |
689 |
|
|
696 |
– |
|
690 |
|
public String toString() { |
691 |
|
final ReentrantLock lock = this.lock; |
692 |
|
lock.lock(); |
875 |
|
throws java.io.IOException { |
876 |
|
lock.lock(); |
877 |
|
try { |
878 |
< |
int n = size; // avoid zero capacity argument |
879 |
< |
q = new PriorityQueue<E>(n == 0 ? 1 : n, comparator); |
878 |
> |
// avoid zero capacity argument |
879 |
> |
q = new PriorityQueue<E>(Math.max(size, 1), comparator); |
880 |
|
q.addAll(this); |
881 |
|
s.defaultWriteObject(); |
882 |
|
} finally { |