--- jsr166/src/main/java/util/PriorityQueue.java 2013/01/19 17:33:55 1.83 +++ jsr166/src/main/java/util/PriorityQueue.java 2013/01/22 19:28:05 1.86 @@ -451,7 +451,9 @@ public class PriorityQueue extends Ab * this queue * @throws NullPointerException if the specified array is null */ + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { + final int size = this.size; if (a.length < size) // Make a new array of a's runtime type, but my contents: return (T[]) Arrays.copyOf(queue, size, a.getClass()); @@ -801,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 @@ -819,7 +820,7 @@ 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 block) { @@ -840,11 +841,11 @@ public class PriorityQueue extends Ab public boolean tryAdvance(Block 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; @@ -853,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; - } } }