91 |
|
* should be used only to detect bugs.</i> |
92 |
|
* |
93 |
|
* <p>This class is a member of the |
94 |
< |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
94 |
> |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
95 |
|
* Java Collections Framework</a>. |
96 |
|
* |
97 |
|
* @param <E> the type of elements in this list |
578 |
|
*/ |
579 |
|
public void clear() { |
580 |
|
modCount++; |
581 |
< |
Arrays.fill(elementData, 0, size, null); |
582 |
< |
size = 0; |
581 |
> |
final Object[] es = elementData; |
582 |
> |
for (int to = size, i = size = 0; i < to; i++) |
583 |
> |
es[i] = null; |
584 |
|
} |
585 |
|
|
586 |
|
/** |
670 |
|
outOfBoundsMsg(fromIndex, toIndex)); |
671 |
|
} |
672 |
|
modCount++; |
673 |
< |
final Object[] es = elementData; |
673 |
< |
final int oldSize = size; |
674 |
< |
System.arraycopy(es, toIndex, es, fromIndex, oldSize - toIndex); |
675 |
< |
Arrays.fill(es, size -= (toIndex - fromIndex), oldSize, null); |
673 |
> |
shiftTailOverGap(elementData, fromIndex, toIndex); |
674 |
|
// checkInvariants(); |
675 |
|
} |
676 |
|
|
677 |
+ |
/** Erases the gap from lo to hi, by sliding down following elements. */ |
678 |
+ |
private void shiftTailOverGap(Object[] es, int lo, int hi) { |
679 |
+ |
System.arraycopy(es, hi, es, lo, size - hi); |
680 |
+ |
for (int to = size, i = (size -= hi - lo); i < to; i++) |
681 |
+ |
es[i] = null; |
682 |
+ |
} |
683 |
+ |
|
684 |
|
/** |
685 |
|
* A version of rangeCheck used by add and addAll. |
686 |
|
*/ |
766 |
|
w += end - r; |
767 |
|
throw ex; |
768 |
|
} finally { |
769 |
< |
final int oldSize = size, deleted = end - w; |
770 |
< |
modCount += deleted; |
766 |
< |
System.arraycopy(es, end, es, w, oldSize - end); |
767 |
< |
Arrays.fill(es, size -= deleted, oldSize, null); |
769 |
> |
modCount += end - w; |
770 |
> |
shiftTailOverGap(es, w, end); |
771 |
|
} |
772 |
|
} |
773 |
|
// checkInvariants(); |
1371 |
|
} |
1372 |
|
} |
1373 |
|
|
1374 |
+ |
/** |
1375 |
+ |
* @throws NullPointerException {@inheritDoc} |
1376 |
+ |
*/ |
1377 |
|
@Override |
1378 |
|
public void forEach(Consumer<? super E> action) { |
1379 |
|
Objects.requireNonNull(action); |
1443 |
|
private int fence; // -1 until used; then one past last index |
1444 |
|
private int expectedModCount; // initialized when fence set |
1445 |
|
|
1446 |
< |
/** Create new spliterator covering the given range */ |
1446 |
> |
/** Creates new spliterator covering the given range. */ |
1447 |
|
ArrayListSpliterator(int origin, int fence, int expectedModCount) { |
1448 |
|
this.index = origin; |
1449 |
|
this.fence = fence; |
1525 |
|
return (bits[i >> 6] & (1L << i)) == 0; |
1526 |
|
} |
1527 |
|
|
1528 |
+ |
/** |
1529 |
+ |
* @throws NullPointerException {@inheritDoc} |
1530 |
+ |
*/ |
1531 |
|
@Override |
1532 |
|
public boolean removeIf(Predicate<? super E> filter) { |
1533 |
|
return removeIf(filter, 0, size); |
1562 |
|
for (i = beg; i < end; i++) |
1563 |
|
if (isClear(deathRow, i - beg)) |
1564 |
|
es[w++] = es[i]; |
1565 |
< |
final int oldSize = size; |
1557 |
< |
System.arraycopy(es, end, es, w, oldSize - end); |
1558 |
< |
Arrays.fill(es, size -= (end - w), oldSize, null); |
1565 |
> |
shiftTailOverGap(es, w, end); |
1566 |
|
// checkInvariants(); |
1567 |
|
return true; |
1568 |
|
} else { |