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.89 by dl, Sun Feb 17 23:36:16 2013 UTC vs.
Revision 1.98 by jsr166, Tue Oct 22 15:21:30 2013 UTC

# Line 26 | Line 26
26   package java.util;
27   import java.util.function.Consumer;
28   import java.util.stream.Stream;
29 import java.util.stream.Streams;
29  
30   /**
31   * An unbounded priority {@linkplain Queue queue} based on a priority heap.
# Line 66 | Line 65 | import java.util.stream.Streams;
65   * java.util.concurrent.PriorityBlockingQueue} class.
66   *
67   * <p>Implementation note: this implementation provides
68 < * O(log(n)) time for the enqueing and dequeing methods
68 > * O(log(n)) time for the enqueuing and dequeuing methods
69   * ({@code offer}, {@code poll}, {@code remove()} and {@code add});
70   * linear time for the {@code remove(Object)} and {@code contains(Object)}
71   * methods; and constant time for the retrieval methods
# Line 744 | Line 743 | public class PriorityQueue<E> extends Ab
743       *             emitted (int), followed by all of its elements
744       *             (each an {@code Object}) in the proper order.
745       * @param s the stream
746 +     * @throws java.io.IOException if an I/O error occurs
747       */
748      private void writeObject(java.io.ObjectOutputStream s)
749          throws java.io.IOException {
# Line 763 | Line 763 | public class PriorityQueue<E> extends Ab
763       * (that is, deserializes it).
764       *
765       * @param s the stream
766 +     * @throws ClassNotFoundException if the class of a serialized object
767 +     *         could not be found
768 +     * @throws java.io.IOException if an I/O error occurs
769       */
770      private void readObject(java.io.ObjectInputStream s)
771          throws java.io.IOException, ClassNotFoundException {
# Line 783 | Line 786 | public class PriorityQueue<E> extends Ab
786          heapify();
787      }
788  
789 <    final Spliterator<E> spliterator() {
789 >    public Spliterator<E> spliterator() {
790          return new PriorityQueueSpliterator<E>(this, 0, -1, 0);
791      }
792  
793 <    public Stream<E> stream() {
794 <        return Streams.stream(spliterator());
795 <    }
796 <
794 <    public Stream<E> parallelStream() {
795 <        return Streams.parallelStream(spliterator());
796 <    }
797 <
793 >    /**
794 >     * This is very similar to ArrayList Spliterator, except for extra
795 >     * null checks.
796 >     */
797      static final class PriorityQueueSpliterator<E> implements Spliterator<E> {
799        /*
800         * This is very similar to ArrayList Spliterator, except for
801         * extra null checks.
802         */
798          private final PriorityQueue<E> pq;
799          private int index;            // current index, modified on advance/split
800          private int fence;            // -1 until first use
801          private int expectedModCount; // initialized when fence set
802  
803 <        /** Create new spliterator covering the given  range */
803 >        /** Creates new spliterator covering the given range */
804          PriorityQueueSpliterator(PriorityQueue<E> pq, int origin, int fence,
805                               int expectedModCount) {
806              this.pq = pq;
# Line 822 | Line 817 | public class PriorityQueue<E> extends Ab
817              }
818              return hi;
819          }
820 <            
821 <        public PriorityQueueSpliterator<E> trySplit() {
820 >
821 >        public Spliterator<E> trySplit() {
822              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
823              return (lo >= mid) ? null :
824 <                new PriorityQueueSpliterator<E>(pq, lo, index = mid,
824 >                new PriorityQueueSpliterator<E>(pq, lo, index = mid,
825                                                  expectedModCount);
826          }
827  
828          @SuppressWarnings("unchecked")
829 <        public void forEach(Consumer<? super E> action) {
829 >        public void forEachRemaining(Consumer<? super E> action) {
830              int i, hi, mc; // hoist accesses and checks from loop
831              PriorityQueue<E> q; Object[] a;
832              if (action == null)
# Line 875 | Line 870 | public class PriorityQueue<E> extends Ab
870              return false;
871          }
872  
873 <        public long estimateSize() {
874 <            return (long) (getFence() - index);
873 >        public long estimateSize() {
874 >            return (long) (getFence() - index);
875          }
876  
877          public int characteristics() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines