247 |
|
} |
248 |
|
|
249 |
|
public E pollFirst() { |
250 |
< |
int h = head; |
250 |
> |
final Object[] elements = this.elements; |
251 |
> |
final int h = head; |
252 |
|
@SuppressWarnings("unchecked") |
253 |
|
E result = (E) elements[h]; |
254 |
|
// Element is null if deque empty |
260 |
|
} |
261 |
|
|
262 |
|
public E pollLast() { |
263 |
< |
int t = (tail - 1) & (elements.length - 1); |
263 |
> |
final Object[] elements = this.elements; |
264 |
> |
final int t = (tail - 1) & (elements.length - 1); |
265 |
|
@SuppressWarnings("unchecked") |
266 |
|
E result = (E) elements[t]; |
267 |
|
if (result != null) { |
608 |
|
} |
609 |
|
lastRet = -1; |
610 |
|
} |
611 |
+ |
|
612 |
+ |
public void forEachRemaining(Consumer<? super E> action) { |
613 |
+ |
Objects.requireNonNull(action); |
614 |
+ |
Object[] a = elements; |
615 |
+ |
int m = a.length - 1, f = fence, i = cursor; |
616 |
+ |
cursor = f; |
617 |
+ |
while (i != f) { |
618 |
+ |
@SuppressWarnings("unchecked") E e = (E)a[i]; |
619 |
+ |
i = (i + 1) & m; |
620 |
+ |
if (e == null) |
621 |
+ |
throw new ConcurrentModificationException(); |
622 |
+ |
action.accept(e); |
623 |
+ |
} |
624 |
+ |
} |
625 |
|
} |
626 |
|
|
627 |
|
/** |
862 |
|
} |
863 |
|
|
864 |
|
public Spliterator<E> spliterator() { |
865 |
< |
return new DeqSpliterator<E>(this, -1, -1); |
865 |
> |
return new DeqSpliterator<>(this, -1, -1); |
866 |
|
} |
867 |
|
|
868 |
|
static final class DeqSpliterator<E> implements Spliterator<E> { |