109 |
|
initialCapacity |= (initialCapacity >>> 16); |
110 |
|
initialCapacity++; |
111 |
|
|
112 |
< |
if (initialCapacity < 0) // Too many elements, must back off |
113 |
< |
initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements |
112 |
> |
if (initialCapacity < 0) // Too many elements, must back off |
113 |
> |
initialCapacity >>>= 1; // Good luck allocating 2^30 elements |
114 |
|
} |
115 |
|
elements = new Object[initialCapacity]; |
116 |
|
} |
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) { |
488 |
|
* |
489 |
|
* @return true if elements moved backwards |
490 |
|
*/ |
491 |
< |
private boolean delete(int i) { |
491 |
> |
boolean delete(int i) { |
492 |
|
checkInvariants(); |
493 |
|
final Object[] elements = this.elements; |
494 |
|
final int mask = elements.length - 1; |
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 |
|
/** |
861 |
|
elements[i] = s.readObject(); |
862 |
|
} |
863 |
|
|
864 |
+ |
/** |
865 |
+ |
* Creates a <em><a href="Spliterator.html#binding">late-binding</a></em> |
866 |
+ |
* and <em>fail-fast</em> {@link Spliterator} over the elements in this |
867 |
+ |
* deque. |
868 |
+ |
* |
869 |
+ |
* <p>The {@code Spliterator} reports {@link Spliterator#SIZED}, |
870 |
+ |
* {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and |
871 |
+ |
* {@link Spliterator#NONNULL}. Overriding implementations should document |
872 |
+ |
* the reporting of additional characteristic values. |
873 |
+ |
* |
874 |
+ |
* @return a {@code Spliterator} over the elements in this deque |
875 |
+ |
* @since 1.8 |
876 |
+ |
*/ |
877 |
|
public Spliterator<E> spliterator() { |
878 |
< |
return new DeqSpliterator<E>(this, -1, -1); |
878 |
> |
return new DeqSpliterator<>(this, -1, -1); |
879 |
|
} |
880 |
|
|
881 |
|
static final class DeqSpliterator<E> implements Spliterator<E> { |