1 |
|
/* |
2 |
< |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 |
> |
* Copyright (c) 2003, 2018, 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 |
26 |
|
package java.util; |
27 |
|
|
28 |
|
import java.util.function.Consumer; |
29 |
+ |
import jdk.internal.misc.SharedSecrets; |
30 |
|
|
31 |
|
/** |
32 |
|
* An unbounded priority {@linkplain Queue queue} based on a priority heap. |
74 |
|
* ({@code peek}, {@code element}, and {@code size}). |
75 |
|
* |
76 |
|
* <p>This class is a member of the |
77 |
< |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
77 |
> |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
78 |
|
* Java Collections Framework</a>. |
79 |
|
* |
80 |
|
* @since 1.5 |
523 |
|
*/ |
524 |
|
private int expectedModCount = modCount; |
525 |
|
|
526 |
+ |
Itr() {} // prevent access constructor creation |
527 |
+ |
|
528 |
|
public boolean hasNext() { |
529 |
|
return cursor < size || |
530 |
|
(forgetMeNot != null && !forgetMeNot.isEmpty()); |
634 |
|
* promoting x up the tree until it is greater than or equal to |
635 |
|
* its parent, or is the root. |
636 |
|
* |
637 |
< |
* To simplify and speed up coercions and comparisons. the |
637 |
> |
* To simplify and speed up coercions and comparisons, the |
638 |
|
* Comparable and Comparator versions are separated into different |
639 |
|
* methods that are otherwise identical. (Similarly for siftDown.) |
640 |
|
* |
735 |
|
@SuppressWarnings("unchecked") |
736 |
|
private void heapify() { |
737 |
|
final Object[] es = queue; |
738 |
< |
final int half = (size >>> 1) - 1; |
738 |
> |
int i = (size >>> 1) - 1; |
739 |
|
if (comparator == null) |
740 |
< |
for (int i = half; i >= 0; i--) |
740 |
> |
for (; i >= 0; i--) |
741 |
|
siftDownComparable(i, (E) es[i]); |
742 |
|
else |
743 |
< |
for (int i = half; i >= 0; i--) |
743 |
> |
for (; i >= 0; i--) |
744 |
|
siftDownUsingComparator(i, (E) es[i]); |
745 |
|
} |
746 |
|
|
796 |
|
// Read in (and discard) array length |
797 |
|
s.readInt(); |
798 |
|
|
799 |
+ |
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size); |
800 |
|
queue = new Object[size]; |
801 |
|
|
802 |
|
// Read in all elements. |
895 |
|
return Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.NONNULL; |
896 |
|
} |
897 |
|
} |
898 |
+ |
|
899 |
+ |
/** |
900 |
+ |
* @throws NullPointerException {@inheritDoc} |
901 |
+ |
*/ |
902 |
+ |
@SuppressWarnings("unchecked") |
903 |
+ |
public void forEach(Consumer<? super E> action) { |
904 |
+ |
Objects.requireNonNull(action); |
905 |
+ |
final int expectedModCount = modCount; |
906 |
+ |
final Object[] es = queue; |
907 |
+ |
for (int i = 0, n = size; i < n; i++) |
908 |
+ |
action.accept((E) es[i]); |
909 |
+ |
if (expectedModCount != modCount) |
910 |
+ |
throw new ConcurrentModificationException(); |
911 |
+ |
} |
912 |
|
} |