183 |
|
* @throws NullPointerException if the specified collection is null |
184 |
|
*/ |
185 |
|
public ArrayDeque(Collection<? extends E> c) { |
186 |
< |
Object[] elements = c.toArray(); |
186 |
> |
Object[] es = c.toArray(); |
187 |
|
// defend against c.toArray (incorrectly) not returning Object[] |
188 |
|
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652) |
189 |
< |
size = elements.length; |
190 |
< |
if (elements.getClass() != Object[].class) |
191 |
< |
elements = Arrays.copyOf(elements, size, Object[].class); |
192 |
< |
for (Object obj : elements) |
189 |
> |
if (es.getClass() != Object[].class) |
190 |
> |
es = Arrays.copyOf(es, es.length, Object[].class); |
191 |
> |
for (Object obj : es) |
192 |
|
Objects.requireNonNull(obj); |
193 |
< |
this.elements = elements; |
193 |
> |
this.elements = es; |
194 |
> |
this.size = es.length; |
195 |
|
} |
196 |
|
|
197 |
|
/** |
263 |
|
public void addFirst(E e) { |
264 |
|
// checkInvariants(); |
265 |
|
Objects.requireNonNull(e); |
266 |
< |
Object[] elements; |
266 |
> |
Object[] es; |
267 |
|
int capacity, h; |
268 |
|
final int s; |
269 |
< |
if ((s = size) == (capacity = (elements = this.elements).length)) { |
269 |
> |
if ((s = size) == (capacity = (es = elements).length)) { |
270 |
|
grow(1); |
271 |
< |
capacity = (elements = this.elements).length; |
271 |
> |
capacity = (es = elements).length; |
272 |
|
} |
273 |
|
if ((h = head - 1) < 0) h = capacity - 1; |
274 |
< |
elements[head = h] = e; |
274 |
> |
es[head = h] = e; |
275 |
|
size = s + 1; |
276 |
|
// checkInvariants(); |
277 |
|
} |
287 |
|
public void addLast(E e) { |
288 |
|
// checkInvariants(); |
289 |
|
Objects.requireNonNull(e); |
290 |
< |
Object[] elements; |
290 |
> |
Object[] es; |
291 |
|
int capacity; |
292 |
|
final int s; |
293 |
< |
if ((s = size) == (capacity = (elements = this.elements).length)) { |
293 |
> |
if ((s = size) == (capacity = (es = elements).length)) { |
294 |
|
grow(1); |
295 |
< |
capacity = (elements = this.elements).length; |
295 |
> |
capacity = (es = elements).length; |
296 |
|
} |
297 |
< |
elements[add(head, s, capacity)] = e; |
297 |
> |
es[add(head, s, capacity)] = e; |
298 |
|
size = s + 1; |
299 |
|
// checkInvariants(); |
300 |
|
} |