--- jsr166/src/main/java/util/PriorityQueue.java 2013/01/19 18:18:10 1.85
+++ jsr166/src/main/java/util/PriorityQueue.java 2013/02/01 01:02:25 1.87
@@ -27,7 +27,7 @@ package java.util;
import java.util.stream.Stream;
import java.util.Spliterator;
import java.util.stream.Streams;
-import java.util.function.Block;
+import java.util.function.Consumer;
/**
* An unbounded priority {@linkplain Queue queue} based on a priority heap.
@@ -64,7 +64,7 @@ import java.util.function.Block;
* Multiple threads should not access a {@code PriorityQueue}
* instance concurrently if any of the threads modifies the queue.
* Instead, use the thread-safe {@link
- * java.util.concurrent.PriorityBlockingQueue} class.
+ * java.util.concurrent.PriorityConsumeringQueue} class.
*
*
Implementation note: this implementation provides
* O(log(n)) time for the enqueing and dequeing methods
@@ -803,8 +803,7 @@ public class PriorityQueue extends Ab
}
/** Index-based split-by-two Spliterator */
- static final class PriorityQueueSpliterator
- implements Spliterator, Iterator {
+ static final class PriorityQueueSpliterator implements Spliterator {
private final PriorityQueue pq;
private int index; // current index, modified on advance/split
private final int fence; // one past last index
@@ -821,10 +820,10 @@ public class PriorityQueue extends Ab
int lo = index, mid = (lo + fence) >>> 1;
return (lo >= mid) ? null :
new PriorityQueueSpliterator(pq, lo, index = mid,
- expectedModCount);
+ expectedModCount);
}
- public void forEach(Block super E> block) {
+ public void forEach(Consumer super E> block) {
Object[] a; int i, hi; // hoist accesses and checks from loop
if (block == null)
throw new NullPointerException();
@@ -840,13 +839,13 @@ public class PriorityQueue extends Ab
}
}
- public boolean tryAdvance(Block super E> block) {
+ public boolean tryAdvance(Consumer super E> block) {
if (index >= 0 && index < fence) {
- if (pq.modCount != expectedModCount)
- throw new ConcurrentModificationException();
@SuppressWarnings("unchecked") E e =
(E)pq.queue[index++];
block.accept(e);
+ if (pq.modCount != expectedModCount)
+ throw new ConcurrentModificationException();
return true;
}
return false;
@@ -855,20 +854,5 @@ public class PriorityQueue extends Ab
public long estimateSize() { return (long)(fence - index); }
public boolean hasExactSize() { return true; }
public boolean hasExactSplits() { return true; }
-
- // Iterator support
- public Iterator iterator() { return this; }
- public void remove() { throw new UnsupportedOperationException(); }
- public boolean hasNext() { return index >= 0 && index < fence; }
-
- public E next() {
- if (index < 0 || index >= fence)
- throw new NoSuchElementException();
- if (pq.modCount != expectedModCount)
- throw new ConcurrentModificationException();
- @SuppressWarnings("unchecked") E e =
- (E) pq.queue[index++];
- return e;
- }
}
}