585 |
|
modCount++; |
586 |
|
elementCount--; |
587 |
|
elementData[elementCount] = null; /* to let gc do its work */ |
588 |
+ |
// checkInvariants(); |
589 |
|
} |
590 |
|
|
591 |
|
/** |
676 |
|
* method (which is part of the {@link List} interface). |
677 |
|
*/ |
678 |
|
public synchronized void removeAllElements() { |
679 |
< |
// Let gc do its work |
679 |
< |
for (int i = 0; i < elementCount; i++) |
680 |
< |
elementData[i] = null; |
681 |
< |
|
679 |
> |
Arrays.fill(elementData, 0, elementCount, null); |
680 |
|
modCount++; |
681 |
|
elementCount = 0; |
682 |
|
} |
808 |
|
elementData = grow(); |
809 |
|
elementData[s] = e; |
810 |
|
elementCount = s + 1; |
811 |
+ |
// checkInvariants(); |
812 |
|
} |
813 |
|
|
814 |
|
/** |
877 |
|
numMoved); |
878 |
|
elementData[--elementCount] = null; // Let gc do its work |
879 |
|
|
880 |
+ |
// checkInvariants(); |
881 |
|
return oldValue; |
882 |
|
} |
883 |
|
|
933 |
|
elementData = grow(s + numNew); |
934 |
|
System.arraycopy(a, 0, elementData, s, numNew); |
935 |
|
elementCount = s + numNew; |
936 |
+ |
// checkInvariants(); |
937 |
|
return true; |
938 |
|
} |
939 |
|
} |
1031 |
|
} |
1032 |
|
if (modCount != expectedModCount) |
1033 |
|
throw new ConcurrentModificationException(); |
1034 |
+ |
// checkInvariants(); |
1035 |
|
return modified; |
1036 |
|
} |
1037 |
|
|
1073 |
|
numMoved); |
1074 |
|
System.arraycopy(a, 0, elementData, index, numNew); |
1075 |
|
elementCount = s + numNew; |
1076 |
+ |
// checkInvariants(); |
1077 |
|
return true; |
1078 |
|
} |
1079 |
|
|
1155 |
|
* (If {@code toIndex==fromIndex}, this operation has no effect.) |
1156 |
|
*/ |
1157 |
|
protected synchronized void removeRange(int fromIndex, int toIndex) { |
1158 |
< |
int numMoved = elementCount - toIndex; |
1159 |
< |
System.arraycopy(elementData, toIndex, elementData, fromIndex, |
1160 |
< |
numMoved); |
1161 |
< |
|
1162 |
< |
// Let gc do its work |
1163 |
< |
modCount++; |
1164 |
< |
int newElementCount = elementCount - (toIndex-fromIndex); |
1162 |
< |
while (elementCount != newElementCount) |
1163 |
< |
elementData[--elementCount] = null; |
1158 |
> |
final Object[] es = elementData; |
1159 |
> |
final int oldSize = elementCount; |
1160 |
> |
System.arraycopy(es, toIndex, es, fromIndex, oldSize - toIndex); |
1161 |
> |
|
1162 |
> |
modCount++; |
1163 |
> |
Arrays.fill(es, elementCount -= (toIndex - fromIndex), oldSize, null); |
1164 |
> |
// checkInvariants(); |
1165 |
|
} |
1166 |
|
|
1167 |
|
/** |
1351 |
|
action.accept(elementAt(es, i)); |
1352 |
|
if (modCount != expectedModCount) |
1353 |
|
throw new ConcurrentModificationException(); |
1354 |
+ |
// checkInvariants(); |
1355 |
|
} |
1356 |
|
|
1357 |
|
@Override |
1365 |
|
if (modCount != expectedModCount) |
1366 |
|
throw new ConcurrentModificationException(); |
1367 |
|
modCount++; |
1368 |
+ |
// checkInvariants(); |
1369 |
|
} |
1370 |
|
|
1371 |
|
@SuppressWarnings("unchecked") |
1373 |
|
public synchronized void sort(Comparator<? super E> c) { |
1374 |
|
final int expectedModCount = modCount; |
1375 |
|
Arrays.sort((E[]) elementData, 0, elementCount, c); |
1376 |
< |
if (modCount != expectedModCount) { |
1376 |
> |
if (modCount != expectedModCount) |
1377 |
|
throw new ConcurrentModificationException(); |
1375 |
– |
} |
1378 |
|
modCount++; |
1379 |
+ |
// checkInvariants(); |
1380 |
|
} |
1381 |
|
|
1382 |
|
/** |
1483 |
|
return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED; |
1484 |
|
} |
1485 |
|
} |
1486 |
+ |
|
1487 |
+ |
void checkInvariants() { |
1488 |
+ |
// assert elementCount >= 0; |
1489 |
+ |
// assert elementCount == elementData.length || elementData[elementCount] == null; |
1490 |
+ |
} |
1491 |
|
} |