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

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.114 by jsr166, Wed Nov 30 18:12:52 2016 UTC vs.
Revision 1.117 by jsr166, Tue Dec 20 22:37:31 2016 UTC

# Line 522 | Line 522 | public class PriorityQueue<E> extends Ab
522           */
523          private int expectedModCount = modCount;
524  
525 +        Itr() {}                        // prevent access constructor creation
526 +
527          public boolean hasNext() {
528              return cursor < size ||
529                  (forgetMeNot != null && !forgetMeNot.isEmpty());
# Line 631 | Line 633 | public class PriorityQueue<E> extends Ab
633       * promoting x up the tree until it is greater than or equal to
634       * its parent, or is the root.
635       *
636 <     * To simplify and speed up coercions and comparisons. the
636 >     * To simplify and speed up coercions and comparisons, the
637       * Comparable and Comparator versions are separated into different
638       * methods that are otherwise identical. (Similarly for siftDown.)
639       *
# Line 823 | Line 825 | public class PriorityQueue<E> extends Ab
825      }
826  
827      final class PriorityQueueSpliterator implements Spliterator<E> {
826        /*
827         * This is very similar to ArrayList Spliterator, except for
828         * extra null checks.
829         */
828          private int index;            // current index, modified on advance/split
829          private int fence;            // -1 until first use
830          private int expectedModCount; // initialized when fence set
# Line 855 | Line 853 | public class PriorityQueue<E> extends Ab
853  
854          @SuppressWarnings("unchecked")
855          public void forEachRemaining(Consumer<? super E> action) {
858            int i, hi, mc; // hoist accesses and checks from loop
859            final Object[] a;
856              if (action == null)
857                  throw new NullPointerException();
858 <            if ((a = queue) != null) {
859 <                if ((hi = fence) < 0) {
860 <                    mc = modCount;
861 <                    hi = size;
862 <                }
863 <                else
864 <                    mc = expectedModCount;
869 <                if ((i = index) >= 0 && (index = hi) <= a.length) {
870 <                    for (E e;; ++i) {
871 <                        if (i < hi) {
872 <                            if ((e = (E) a[i]) == null) // must be CME
873 <                                break;
874 <                            action.accept(e);
875 <                        }
876 <                        else if (modCount != mc)
877 <                            break;
878 <                        else
879 <                            return;
880 <                    }
881 <                }
858 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
859 >            final Object[] a = queue;
860 >            int i, hi; E e;
861 >            for (i = index, index = hi = fence; i < hi; i++) {
862 >                if ((e = (E) a[i]) == null)
863 >                    break;      // must be CME
864 >                action.accept(e);
865              }
866 <            throw new ConcurrentModificationException();
866 >            if (modCount != expectedModCount)
867 >                throw new ConcurrentModificationException();
868          }
869  
870 +        @SuppressWarnings("unchecked")
871          public boolean tryAdvance(Consumer<? super E> action) {
872              if (action == null)
873                  throw new NullPointerException();
874 <            int hi = getFence(), lo = index;
875 <            if (lo >= 0 && lo < hi) {
876 <                index = lo + 1;
877 <                @SuppressWarnings("unchecked") E e = (E)queue[lo];
878 <                if (e == null)
874 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
875 >            int i;
876 >            if ((i = index) < fence) {
877 >                index = i + 1;
878 >                E e;
879 >                if ((e = (E) queue[i]) == null
880 >                    || modCount != expectedModCount)
881                      throw new ConcurrentModificationException();
882                  action.accept(e);
896                if (modCount != expectedModCount)
897                    throw new ConcurrentModificationException();
883                  return true;
884              }
885              return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines