--- jsr166/src/main/java/util/PriorityQueue.java 2013/02/17 23:36:16 1.89
+++ jsr166/src/main/java/util/PriorityQueue.java 2014/08/29 21:42:37 1.100
@@ -26,7 +26,6 @@
package java.util;
import java.util.function.Consumer;
import java.util.stream.Stream;
-import java.util.stream.Streams;
/**
* An unbounded priority {@linkplain Queue queue} based on a priority heap.
@@ -66,7 +65,7 @@ import java.util.stream.Streams;
* java.util.concurrent.PriorityBlockingQueue} class.
*
*
Implementation note: this implementation provides
- * O(log(n)) time for the enqueing and dequeing methods
+ * O(log(n)) time for the enqueuing and dequeuing methods
* ({@code offer}, {@code poll}, {@code remove()} and {@code add});
* linear time for the {@code remove(Object)} and {@code contains(Object)}
* methods; and constant time for the retrieval methods
@@ -100,7 +99,7 @@ public class PriorityQueue extends Ab
/**
* The number of elements in the priority queue.
*/
- private int size = 0;
+ private int size;
/**
* The comparator, or null if priority queue uses elements'
@@ -394,7 +393,7 @@ public class PriorityQueue extends Ab
* @return {@code true} if this queue contains the specified element
*/
public boolean contains(Object o) {
- return indexOf(o) != -1;
+ return indexOf(o) >= 0;
}
/**
@@ -477,7 +476,7 @@ public class PriorityQueue extends Ab
* Index (into queue array) of element to be returned by
* subsequent call to next.
*/
- private int cursor = 0;
+ private int cursor;
/**
* Index of element returned by most recent call to next,
@@ -497,13 +496,13 @@ public class PriorityQueue extends Ab
* We expect that most iterations, even those involving removals,
* will not need to store elements in this field.
*/
- private ArrayDeque forgetMeNot = null;
+ private ArrayDeque forgetMeNot;
/**
* Element returned by the most recent call to next iff that
* element was drawn from the forgetMeNot list.
*/
- private E lastRetElt = null;
+ private E lastRetElt;
/**
* The modCount value that the iterator believes that the backing
@@ -744,6 +743,7 @@ public class PriorityQueue extends Ab
* emitted (int), followed by all of its elements
* (each an {@code Object}) in the proper order.
* @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
@@ -763,6 +763,9 @@ public class PriorityQueue extends Ab
* (that is, deserializes it).
*
* @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
@@ -783,29 +786,21 @@ public class PriorityQueue extends Ab
heapify();
}
- final Spliterator spliterator() {
+ public Spliterator spliterator() {
return new PriorityQueueSpliterator(this, 0, -1, 0);
}
- public Stream stream() {
- return Streams.stream(spliterator());
- }
-
- public Stream parallelStream() {
- return Streams.parallelStream(spliterator());
- }
-
+ /**
+ * This is very similar to ArrayList Spliterator, except for extra
+ * null checks.
+ */
static final class PriorityQueueSpliterator implements Spliterator {
- /*
- * This is very similar to ArrayList Spliterator, except for
- * extra null checks.
- */
private final PriorityQueue pq;
private int index; // current index, modified on advance/split
private int fence; // -1 until first use
private int expectedModCount; // initialized when fence set
- /** Create new spliterator covering the given range */
+ /** Creates new spliterator covering the given range */
PriorityQueueSpliterator(PriorityQueue pq, int origin, int fence,
int expectedModCount) {
this.pq = pq;
@@ -822,16 +817,16 @@ public class PriorityQueue extends Ab
}
return hi;
}
-
- public PriorityQueueSpliterator trySplit() {
+
+ public Spliterator trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid) ? null :
- new PriorityQueueSpliterator(pq, lo, index = mid,
+ new PriorityQueueSpliterator(pq, lo, index = mid,
expectedModCount);
}
@SuppressWarnings("unchecked")
- public void forEach(Consumer super E> action) {
+ public void forEachRemaining(Consumer super E> action) {
int i, hi, mc; // hoist accesses and checks from loop
PriorityQueue q; Object[] a;
if (action == null)
@@ -875,8 +870,8 @@ public class PriorityQueue extends Ab
return false;
}
- public long estimateSize() {
- return (long) (getFence() - index);
+ public long estimateSize() {
+ return (long) (getFence() - index);
}
public int characteristics() {