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.105 by jsr166, Fri Feb 27 19:01:11 2015 UTC vs.
Revision 1.106 by jsr166, Tue Jun 16 23:06:01 2015 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 111 | Line 111 | public class PriorityQueue<E> extends Ab
111       * The number of times this priority queue has been
112       * <i>structurally modified</i>.  See AbstractList for gory details.
113       */
114 <    transient int modCount;     // non-private for nested class access
114 >    transient int modCount;     // non-private to simplify nested class access
115  
116      /**
117       * Creates a {@code PriorityQueue} with the default initial
# Line 136 | Line 136 | public class PriorityQueue<E> extends Ab
136      }
137  
138      /**
139 +     * Creates a {@code PriorityQueue} with the default initial capacity and
140 +     * whose elements are ordered according to the specified comparator.
141 +     *
142 +     * @param  comparator the comparator that will be used to order this
143 +     *         priority queue.  If {@code null}, the {@linkplain Comparable
144 +     *         natural ordering} of the elements will be used.
145 +     * @since 1.8
146 +     */
147 +    public PriorityQueue(Comparator<? super E> comparator) {
148 +        this(DEFAULT_INITIAL_CAPACITY, comparator);
149 +    }
150 +
151 +    /**
152       * Creates a {@code PriorityQueue} with the specified initial capacity
153       * that orders its elements according to the specified comparator.
154       *
# Line 245 | Line 258 | public class PriorityQueue<E> extends Ab
258              a = Arrays.copyOf(a, a.length, Object[].class);
259          int len = a.length;
260          if (len == 1 || this.comparator != null)
261 <            for (int i = 0; i < len; i++)
262 <                if (a[i] == null)
261 >            for (Object e : a)
262 >                if (e == null)
263                      throw new NullPointerException();
264          this.queue = a;
265          this.size = a.length;
# Line 786 | Line 799 | public class PriorityQueue<E> extends Ab
799          heapify();
800      }
801  
789    public Spliterator<E> spliterator() {
790        return new PriorityQueueSpliterator<E>(this, 0, -1, 0);
791    }
792
802      /**
803 <     * This is very similar to ArrayList Spliterator, except for extra
804 <     * null checks.
803 >     * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
804 >     * and <em>fail-fast</em> {@link Spliterator} over the elements in this
805 >     * queue.
806 >     *
807 >     * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
808 >     * {@link Spliterator#SUBSIZED}, and {@link Spliterator#NONNULL}.
809 >     * Overriding implementations should document the reporting of additional
810 >     * characteristic values.
811 >     *
812 >     * @return a {@code Spliterator} over the elements in this queue
813 >     * @since 1.8
814       */
815 +    public final Spliterator<E> spliterator() {
816 +        return new PriorityQueueSpliterator<>(this, 0, -1, 0);
817 +    }
818 +
819      static final class PriorityQueueSpliterator<E> implements Spliterator<E> {
820 +        /*
821 +         * This is very similar to ArrayList Spliterator, except for
822 +         * extra null checks.
823 +         */
824          private final PriorityQueue<E> pq;
825          private int index;            // current index, modified on advance/split
826          private int fence;            // -1 until first use
# Line 818 | Line 844 | public class PriorityQueue<E> extends Ab
844              return hi;
845          }
846  
847 <        public Spliterator<E> trySplit() {
847 >        public PriorityQueueSpliterator<E> trySplit() {
848              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
849              return (lo >= mid) ? null :
850 <                new PriorityQueueSpliterator<E>(pq, lo, index = mid,
851 <                                                expectedModCount);
850 >                new PriorityQueueSpliterator<>(pq, lo, index = mid,
851 >                                               expectedModCount);
852          }
853  
854          @SuppressWarnings("unchecked")
# Line 856 | Line 882 | public class PriorityQueue<E> extends Ab
882          }
883  
884          public boolean tryAdvance(Consumer<? super E> action) {
885 +            if (action == null)
886 +                throw new NullPointerException();
887              int hi = getFence(), lo = index;
888              if (lo >= 0 && lo < hi) {
889                  index = lo + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines