ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java (file contents):
Revision 1.77 by jsr166, Fri Jul 1 19:00:32 2011 UTC vs.
Revision 1.78 by jsr166, Fri Jul 1 19:39:07 2011 UTC

# Line 614 | Line 614 | public class PriorityBlockingQueue<E> ex
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       */
# Line 638 | Line 635 | public class PriorityBlockingQueue<E> ex
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;
# Line 659 | Line 655 | public class PriorityBlockingQueue<E> ex
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      /**
# Line 693 | Line 687 | public class PriorityBlockingQueue<E> ex
687          }
688      }
689  
696
690      public String toString() {
691          final ReentrantLock lock = this.lock;
692          lock.lock();
# Line 882 | Line 875 | public class PriorityBlockingQueue<E> ex
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 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines