501 |
|
s - index); |
502 |
|
elementData[index] = element; |
503 |
|
size = s + 1; |
504 |
+ |
// checkInvariants(); |
505 |
|
} |
506 |
|
|
507 |
|
/** |
525 |
|
numMoved); |
526 |
|
elementData[--size] = null; // clear to let GC do its work |
527 |
|
|
528 |
+ |
// checkInvariants(); |
529 |
|
return oldValue; |
530 |
|
} |
531 |
|
|
559 |
|
return false; |
560 |
|
} |
561 |
|
|
562 |
< |
/* |
562 |
> |
/** |
563 |
|
* Private remove method that skips bounds checking and does not |
564 |
|
* return the value removed. |
565 |
|
*/ |
578 |
|
*/ |
579 |
|
public void clear() { |
580 |
|
modCount++; |
581 |
< |
|
580 |
< |
// clear to let GC do its work |
581 |
< |
for (int i = 0; i < size; i++) |
582 |
< |
elementData[i] = null; |
583 |
< |
|
581 |
> |
Arrays.fill(elementData, 0, size, null); |
582 |
|
size = 0; |
583 |
|
} |
584 |
|
|
607 |
|
elementData = grow(s + numNew); |
608 |
|
System.arraycopy(a, 0, elementData, s, numNew); |
609 |
|
size = s + numNew; |
610 |
+ |
// checkInvariants(); |
611 |
|
return true; |
612 |
|
} |
613 |
|
|
646 |
|
numMoved); |
647 |
|
System.arraycopy(a, 0, elementData, index, numNew); |
648 |
|
size = s + numNew; |
649 |
+ |
// checkInvariants(); |
650 |
|
return true; |
651 |
|
} |
652 |
|
|
669 |
|
outOfBoundsMsg(fromIndex, toIndex)); |
670 |
|
} |
671 |
|
modCount++; |
672 |
< |
int numMoved = size - toIndex; |
673 |
< |
System.arraycopy(elementData, toIndex, elementData, fromIndex, |
674 |
< |
numMoved); |
675 |
< |
|
676 |
< |
// clear to let GC do its work |
677 |
< |
int newSize = size - (toIndex-fromIndex); |
678 |
< |
for (int i = newSize; i < size; i++) { |
679 |
< |
elementData[i] = null; |
680 |
< |
} |
681 |
< |
size = newSize; |
672 |
> |
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); |
676 |
> |
// checkInvariants(); |
677 |
|
} |
678 |
|
|
679 |
|
/** |
767 |
|
Arrays.fill(es, size -= deleted, oldSize, null); |
768 |
|
} |
769 |
|
} |
770 |
+ |
// checkInvariants(); |
771 |
|
return modified; |
772 |
|
} |
773 |
|
|
1120 |
|
public boolean removeAll(Collection<?> c) { |
1121 |
|
return batchRemove(c, false); |
1122 |
|
} |
1123 |
+ |
|
1124 |
|
public boolean retainAll(Collection<?> c) { |
1125 |
|
return batchRemove(c, true); |
1126 |
|
} |
1377 |
|
final int expectedModCount = modCount; |
1378 |
|
final Object[] es = elementData; |
1379 |
|
final int size = this.size; |
1380 |
< |
for (int i = 0; modCount == expectedModCount && i < size; i++) { |
1380 |
> |
for (int i = 0; modCount == expectedModCount && i < size; i++) |
1381 |
|
action.accept(elementAt(es, i)); |
1382 |
< |
} |
1386 |
< |
if (modCount != expectedModCount) { |
1382 |
> |
if (modCount != expectedModCount) |
1383 |
|
throw new ConcurrentModificationException(); |
1388 |
– |
} |
1384 |
|
} |
1385 |
|
|
1386 |
|
/** |
1570 |
|
} |
1571 |
|
if (modCount != expectedModCount) |
1572 |
|
throw new ConcurrentModificationException(); |
1573 |
+ |
// checkInvariants(); |
1574 |
|
return modified; |
1575 |
|
} |
1576 |
|
|
1580 |
|
final int expectedModCount = modCount; |
1581 |
|
final Object[] es = elementData; |
1582 |
|
final int size = this.size; |
1583 |
< |
for (int i=0; modCount == expectedModCount && i < size; i++) { |
1583 |
> |
for (int i = 0; modCount == expectedModCount && i < size; i++) |
1584 |
|
es[i] = operator.apply(elementAt(es, i)); |
1585 |
< |
} |
1590 |
< |
if (modCount != expectedModCount) { |
1585 |
> |
if (modCount != expectedModCount) |
1586 |
|
throw new ConcurrentModificationException(); |
1592 |
– |
} |
1587 |
|
modCount++; |
1588 |
+ |
// checkInvariants(); |
1589 |
|
} |
1590 |
|
|
1591 |
|
@Override |
1593 |
|
public void sort(Comparator<? super E> c) { |
1594 |
|
final int expectedModCount = modCount; |
1595 |
|
Arrays.sort((E[]) elementData, 0, size, c); |
1596 |
< |
if (modCount != expectedModCount) { |
1596 |
> |
if (modCount != expectedModCount) |
1597 |
|
throw new ConcurrentModificationException(); |
1603 |
– |
} |
1598 |
|
modCount++; |
1599 |
+ |
// checkInvariants(); |
1600 |
+ |
} |
1601 |
+ |
|
1602 |
+ |
void checkInvariants() { |
1603 |
+ |
// assert size >= 0; |
1604 |
+ |
// assert size == elementData.length || elementData[size] == null; |
1605 |
|
} |
1606 |
|
} |