50 |
|
* Iterator} interfaces. |
51 |
|
* |
52 |
|
* <p>This class is a member of the |
53 |
< |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
53 |
> |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
54 |
|
* Java Collections Framework</a>. |
55 |
|
* |
56 |
|
* @author Josh Bloch and Doug Lea |
117 |
|
if (jump < needed |
118 |
|
|| (newCapacity = (oldCapacity + jump)) - MAX_ARRAY_SIZE > 0) |
119 |
|
newCapacity = newCapacity(needed, jump); |
120 |
< |
elements = Arrays.copyOf(elements, newCapacity); |
120 |
> |
final Object[] es = elements = Arrays.copyOf(elements, newCapacity); |
121 |
|
// Exceptionally, here tail == head needs to be disambiguated |
122 |
< |
if (tail < head || (tail == head && elements[head] != null)) { |
122 |
> |
if (tail < head || (tail == head && es[head] != null)) { |
123 |
|
// wrap around; slide first leg forward to end of array |
124 |
|
int newSpace = newCapacity - oldCapacity; |
125 |
< |
System.arraycopy(elements, head, |
126 |
< |
elements, head + newSpace, |
125 |
> |
System.arraycopy(es, head, |
126 |
> |
es, head + newSpace, |
127 |
|
oldCapacity - head); |
128 |
< |
Arrays.fill(elements, head, head + newSpace, null); |
129 |
< |
head += newSpace; |
128 |
> |
for (int i = head, to = (head += newSpace); i < to; i++) |
129 |
> |
es[i] = null; |
130 |
|
} |
131 |
|
// checkInvariants(); |
132 |
|
} |
244 |
|
* Index i must be logically ahead of index j. |
245 |
|
* Precondition: 0 <= i < modulus, 0 <= j < modulus. |
246 |
|
* @return the "circular distance" from j to i; corner case i == j |
247 |
< |
* is diambiguated to "empty", returning 0. |
247 |
> |
* is disambiguated to "empty", returning 0. |
248 |
|
*/ |
249 |
|
static final int sub(int i, int j, int modulus) { |
250 |
|
if ((i -= j) < 0) i += modulus; |
313 |
|
/** |
314 |
|
* Adds all of the elements in the specified collection at the end |
315 |
|
* of this deque, as if by calling {@link #addLast} on each one, |
316 |
< |
* in the order that they are returned by the collection's |
317 |
< |
* iterator. |
316 |
> |
* in the order that they are returned by the collection's iterator. |
317 |
|
* |
318 |
|
* @param c the elements to be inserted into this deque |
319 |
|
* @return {@code true} if this deque changed as a result of the call |
519 |
|
/** |
520 |
|
* Retrieves and removes the head of the queue represented by this deque. |
521 |
|
* |
522 |
< |
* This method differs from {@link #poll poll} only in that it throws an |
523 |
< |
* exception if this deque is empty. |
522 |
> |
* This method differs from {@link #poll() poll()} only in that it |
523 |
> |
* throws an exception if this deque is empty. |
524 |
|
* |
525 |
|
* <p>This method is equivalent to {@link #removeFirst}. |
526 |
|
* |
887 |
|
} |
888 |
|
} |
889 |
|
|
890 |
+ |
/** |
891 |
+ |
* @throws NullPointerException {@inheritDoc} |
892 |
+ |
*/ |
893 |
|
public void forEach(Consumer<? super E> action) { |
894 |
|
Objects.requireNonNull(action); |
895 |
|
final Object[] es = elements; |
1078 |
|
|
1079 |
|
/** |
1080 |
|
* Nulls out slots starting at array index i, upto index end. |
1081 |
+ |
* Condition i == end means "empty" - nothing to do. |
1082 |
|
*/ |
1083 |
|
private static void circularClear(Object[] es, int i, int end) { |
1084 |
+ |
// assert 0 <= i && i < es.length; |
1085 |
+ |
// assert 0 <= end && end < es.length; |
1086 |
|
for (int to = (i <= end) ? end : es.length; |
1087 |
|
; i = 0, to = end) { |
1088 |
< |
Arrays.fill(es, i, to, null); |
1088 |
> |
for (; i < to; i++) es[i] = null; |
1089 |
|
if (to == end) break; |
1090 |
|
} |
1091 |
|
} |