317 |
|
* @throws NullPointerException if the specified collection or any |
318 |
|
* of its elements are null |
319 |
|
*/ |
320 |
– |
@Override |
320 |
|
public boolean addAll(Collection<? extends E> c) { |
321 |
+ |
final int s = size, needed = c.size() - (elements.length - s); |
322 |
+ |
if (needed > 0) |
323 |
+ |
grow(needed); |
324 |
+ |
c.forEach((e) -> addLast(e)); |
325 |
|
// checkInvariants(); |
326 |
< |
Object[] a, elements; |
324 |
< |
int newcomers, capacity, s = size; |
325 |
< |
if ((newcomers = (a = c.toArray()).length) == 0) |
326 |
< |
return false; |
327 |
< |
while ((capacity = (elements = this.elements).length) - s < newcomers) |
328 |
< |
grow(newcomers - (capacity - s)); |
329 |
< |
int i = add(head, s, capacity); |
330 |
< |
for (Object x : a) { |
331 |
< |
Objects.requireNonNull(x); |
332 |
< |
elements[i] = x; |
333 |
< |
i = inc(i, capacity); |
334 |
< |
size++; |
335 |
< |
} |
336 |
< |
return true; |
326 |
> |
return size > s; |
327 |
|
} |
328 |
|
|
329 |
|
/** |
845 |
|
} |
846 |
|
} |
847 |
|
|
858 |
– |
@Override |
848 |
|
public void forEach(Consumer<? super E> action) { |
849 |
|
// checkInvariants(); |
850 |
|
Objects.requireNonNull(action); |
874 |
|
/** |
875 |
|
* @throws NullPointerException {@inheritDoc} |
876 |
|
*/ |
888 |
– |
@Override |
877 |
|
public boolean removeIf(Predicate<? super E> filter) { |
878 |
|
Objects.requireNonNull(filter); |
879 |
|
return bulkRemove(filter); |
882 |
|
/** |
883 |
|
* @throws NullPointerException {@inheritDoc} |
884 |
|
*/ |
897 |
– |
@Override |
885 |
|
public boolean removeAll(Collection<?> c) { |
886 |
|
Objects.requireNonNull(c); |
887 |
|
return bulkRemove(e -> c.contains(e)); |
890 |
|
/** |
891 |
|
* @throws NullPointerException {@inheritDoc} |
892 |
|
*/ |
906 |
– |
@Override |
893 |
|
public boolean retainAll(Collection<?> c) { |
894 |
|
Objects.requireNonNull(c); |
895 |
|
return bulkRemove(e -> !c.contains(e)); |