ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayList.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayList.java (file contents):
Revision 1.37 by jsr166, Fri Nov 4 03:09:27 2016 UTC vs.
Revision 1.53 by jsr166, Mon Jul 3 20:08:10 2017 UTC

# Line 91 | Line 91 | import java.util.function.UnaryOperator;
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
# Line 423 | Line 423 | public class ArrayList<E> extends Abstra
423          return (E) elementData[index];
424      }
425  
426 +    @SuppressWarnings("unchecked")
427 +    static <E> E elementAt(Object[] es, int index) {
428 +        return (E) es[index];
429 +    }
430 +
431      /**
432       * Returns the element at the specified position in this list.
433       *
# Line 496 | Line 501 | public class ArrayList<E> extends Abstra
501                           s - index);
502          elementData[index] = element;
503          size = s + 1;
504 +        // checkInvariants();
505      }
506  
507      /**
# Line 509 | Line 515 | public class ArrayList<E> extends Abstra
515       */
516      public E remove(int index) {
517          Objects.checkIndex(index, size);
518 +        final Object[] es = elementData;
519  
520 <        modCount++;
521 <        E oldValue = elementData(index);
515 <
516 <        int numMoved = size - index - 1;
517 <        if (numMoved > 0)
518 <            System.arraycopy(elementData, index+1, elementData, index,
519 <                             numMoved);
520 <        elementData[--size] = null; // clear to let GC do its work
520 >        @SuppressWarnings("unchecked") E oldValue = (E) es[index];
521 >        fastRemove(es, index);
522  
523 +        // checkInvariants();
524          return oldValue;
525      }
526  
# Line 536 | Line 538 | public class ArrayList<E> extends Abstra
538       * @return {@code true} if this list contained the specified element
539       */
540      public boolean remove(Object o) {
541 <        if (o == null) {
542 <            for (int index = 0; index < size; index++)
543 <                if (elementData[index] == null) {
544 <                    fastRemove(index);
545 <                    return true;
546 <                }
547 <        } else {
548 <            for (int index = 0; index < size; index++)
549 <                if (o.equals(elementData[index])) {
550 <                    fastRemove(index);
551 <                    return true;
552 <                }
541 >        final Object[] es = elementData;
542 >        final int size = this.size;
543 >        int i = 0;
544 >        found: {
545 >            if (o == null) {
546 >                for (; i < size; i++)
547 >                    if (es[i] == null)
548 >                        break found;
549 >            } else {
550 >                for (; i < size; i++)
551 >                    if (o.equals(es[i]))
552 >                        break found;
553 >            }
554 >            return false;
555          }
556 <        return false;
556 >        fastRemove(es, i);
557 >        return true;
558      }
559  
560 <    /*
560 >    /**
561       * Private remove method that skips bounds checking and does not
562       * return the value removed.
563       */
564 <    private void fastRemove(int index) {
564 >    private void fastRemove(Object[] es, int i) {
565          modCount++;
566 <        int numMoved = size - index - 1;
567 <        if (numMoved > 0)
568 <            System.arraycopy(elementData, index+1, elementData, index,
569 <                             numMoved);
565 <        elementData[--size] = null; // clear to let GC do its work
566 >        final int newSize;
567 >        if ((newSize = size - 1) > i)
568 >            System.arraycopy(es, i + 1, es, i, newSize - i);
569 >        es[size = newSize] = null;
570      }
571  
572      /**
# Line 571 | Line 575 | public class ArrayList<E> extends Abstra
575       */
576      public void clear() {
577          modCount++;
578 <
579 <        // clear to let GC do its work
580 <        for (int i = 0; i < size; i++)
577 <            elementData[i] = null;
578 <
579 <        size = 0;
578 >        final Object[] es = elementData;
579 >        for (int to = size, i = size = 0; i < to; i++)
580 >            es[i] = null;
581      }
582  
583      /**
# Line 604 | Line 605 | public class ArrayList<E> extends Abstra
605              elementData = grow(s + numNew);
606          System.arraycopy(a, 0, elementData, s, numNew);
607          size = s + numNew;
608 +        // checkInvariants();
609          return true;
610      }
611  
# Line 642 | Line 644 | public class ArrayList<E> extends Abstra
644                               numMoved);
645          System.arraycopy(a, 0, elementData, index, numNew);
646          size = s + numNew;
647 +        // checkInvariants();
648          return true;
649      }
650  
# Line 664 | Line 667 | public class ArrayList<E> extends Abstra
667                      outOfBoundsMsg(fromIndex, toIndex));
668          }
669          modCount++;
670 <        int numMoved = size - toIndex;
671 <        System.arraycopy(elementData, toIndex, elementData, fromIndex,
672 <                         numMoved);
673 <
674 <        // clear to let GC do its work
675 <        int newSize = size - (toIndex-fromIndex);
676 <        for (int i = newSize; i < size; i++) {
677 <            elementData[i] = null;
678 <        }
676 <        size = newSize;
670 >        shiftTailOverGap(elementData, fromIndex, toIndex);
671 >        // checkInvariants();
672 >    }
673 >
674 >    /** Erases the gap from lo to hi, by sliding down following elements. */
675 >    private void shiftTailOverGap(Object[] es, int lo, int hi) {
676 >        System.arraycopy(es, hi, es, lo, size - hi);
677 >        for (int to = size, i = (size -= hi - lo); i < to; i++)
678 >            es[i] = null;
679      }
680  
681      /**
# Line 716 | Line 718 | public class ArrayList<E> extends Abstra
718       * @see Collection#contains(Object)
719       */
720      public boolean removeAll(Collection<?> c) {
721 <        return batchRemove(c, false);
721 >        return batchRemove(c, false, 0, size);
722      }
723  
724      /**
# Line 736 | Line 738 | public class ArrayList<E> extends Abstra
738       * @see Collection#contains(Object)
739       */
740      public boolean retainAll(Collection<?> c) {
741 <        return batchRemove(c, true);
741 >        return batchRemove(c, true, 0, size);
742      }
743  
744 <    private boolean batchRemove(Collection<?> c, boolean complement) {
744 >    boolean batchRemove(Collection<?> c, boolean complement,
745 >                        final int from, final int end) {
746          Objects.requireNonNull(c);
747          final Object[] es = elementData;
745        final int size = this.size;
746        final boolean modified;
748          int r;
749          // Optimize for initial run of survivors
750 <        for (r = 0; r < size; r++)
750 >        for (r = from;; r++) {
751 >            if (r == end)
752 >                return false;
753              if (c.contains(es[r]) != complement)
754                  break;
752        if (modified = (r < size)) {
753            int w = r++;
754            try {
755                for (Object e; r < size; r++)
756                    if (c.contains(e = es[r]) == complement)
757                        es[w++] = e;
758            } catch (Throwable ex) {
759                // Preserve behavioral compatibility with AbstractCollection,
760                // even if c.contains() throws.
761                System.arraycopy(es, r, es, w, size - r);
762                w += size - r;
763                throw ex;
764            } finally {
765                modCount += size - w;
766                Arrays.fill(es, (this.size = w), size, null);
767            }
755          }
756 <        return modified;
756 >        int w = r++;
757 >        try {
758 >            for (Object e; r < end; r++)
759 >                if (c.contains(e = es[r]) == complement)
760 >                    es[w++] = e;
761 >        } catch (Throwable ex) {
762 >            // Preserve behavioral compatibility with AbstractCollection,
763 >            // even if c.contains() throws.
764 >            System.arraycopy(es, r, es, w, end - r);
765 >            w += end - r;
766 >            throw ex;
767 >        } finally {
768 >            modCount += end - w;
769 >            shiftTailOverGap(es, w, end);
770 >        }
771 >        // checkInvariants();
772 >        return true;
773      }
774  
775      /**
776 <     * Save the state of the {@code ArrayList} instance to a stream (that
777 <     * is, serialize it).
776 >     * Saves the state of the {@code ArrayList} instance to a stream
777 >     * (that is, serializes it).
778       *
779 +     * @param s the stream
780 +     * @throws java.io.IOException if an I/O error occurs
781       * @serialData The length of the array backing the {@code ArrayList}
782       *             instance is emitted (int), followed by all of its elements
783       *             (each an {@code Object}) in the proper order.
784       */
785      private void writeObject(java.io.ObjectOutputStream s)
786 <        throws java.io.IOException{
786 >        throws java.io.IOException {
787          // Write out element count, and any hidden stuff
788          int expectedModCount = modCount;
789          s.defaultWriteObject();
790  
791 <        // Write out size as capacity for behavioural compatibility with clone()
791 >        // Write out size as capacity for behavioral compatibility with clone()
792          s.writeInt(size);
793  
794          // Write out all elements in the proper order.
# Line 797 | Line 802 | public class ArrayList<E> extends Abstra
802      }
803  
804      /**
805 <     * Reconstitute the {@code ArrayList} instance from a stream (that is,
806 <     * deserialize it).
805 >     * Reconstitutes the {@code ArrayList} instance from a stream (that is,
806 >     * deserializes it).
807 >     * @param s the stream
808 >     * @throws ClassNotFoundException if the class of a serialized object
809 >     *         could not be found
810 >     * @throws java.io.IOException if an I/O error occurs
811       */
812      private void readObject(java.io.ObjectInputStream s)
813          throws java.io.IOException, ClassNotFoundException {
# Line 910 | Line 919 | public class ArrayList<E> extends Abstra
919          }
920  
921          @Override
922 <        @SuppressWarnings("unchecked")
923 <        public void forEachRemaining(Consumer<? super E> consumer) {
915 <            Objects.requireNonNull(consumer);
922 >        public void forEachRemaining(Consumer<? super E> action) {
923 >            Objects.requireNonNull(action);
924              final int size = ArrayList.this.size;
925              int i = cursor;
926 <            if (i >= size) {
927 <                return;
928 <            }
929 <            final Object[] elementData = ArrayList.this.elementData;
930 <            if (i >= elementData.length) {
931 <                throw new ConcurrentModificationException();
932 <            }
933 <            while (i != size && modCount == expectedModCount) {
934 <                consumer.accept((E) elementData[i++]);
926 >            if (i < size) {
927 >                final Object[] es = elementData;
928 >                if (i >= es.length)
929 >                    throw new ConcurrentModificationException();
930 >                for (; i < size && modCount == expectedModCount; i++)
931 >                    action.accept(elementAt(es, i));
932 >                // update once at end to reduce heap write traffic
933 >                cursor = i;
934 >                lastRet = i - 1;
935 >                checkForComodification();
936              }
928            // update once at end of iteration to reduce heap write traffic
929            cursor = i;
930            lastRet = i - 1;
931            checkForComodification();
937          }
938  
939          final void checkForComodification() {
# Line 1115 | Line 1120 | public class ArrayList<E> extends Abstra
1120              return true;
1121          }
1122  
1123 +        public boolean removeAll(Collection<?> c) {
1124 +            return batchRemove(c, false);
1125 +        }
1126 +
1127 +        public boolean retainAll(Collection<?> c) {
1128 +            return batchRemove(c, true);
1129 +        }
1130 +
1131 +        private boolean batchRemove(Collection<?> c, boolean complement) {
1132 +            checkForComodification();
1133 +            int oldSize = root.size;
1134 +            boolean modified =
1135 +                root.batchRemove(c, complement, offset, offset + size);
1136 +            if (modified)
1137 +                updateSizeAndModCount(root.size - oldSize);
1138 +            return modified;
1139 +        }
1140 +
1141 +        public boolean removeIf(Predicate<? super E> filter) {
1142 +            checkForComodification();
1143 +            int oldSize = root.size;
1144 +            boolean modified = root.removeIf(filter, offset, offset + size);
1145 +            if (modified)
1146 +                updateSizeAndModCount(root.size - oldSize);
1147 +            return modified;
1148 +        }
1149 +
1150          public Iterator<E> iterator() {
1151              return listIterator();
1152          }
# Line 1162 | Line 1194 | public class ArrayList<E> extends Abstra
1194                      return (E) elementData[offset + (lastRet = i)];
1195                  }
1196  
1197 <                @SuppressWarnings("unchecked")
1198 <                public void forEachRemaining(Consumer<? super E> consumer) {
1167 <                    Objects.requireNonNull(consumer);
1197 >                public void forEachRemaining(Consumer<? super E> action) {
1198 >                    Objects.requireNonNull(action);
1199                      final int size = SubList.this.size;
1200                      int i = cursor;
1201 <                    if (i >= size) {
1202 <                        return;
1203 <                    }
1204 <                    final Object[] elementData = root.elementData;
1205 <                    if (offset + i >= elementData.length) {
1206 <                        throw new ConcurrentModificationException();
1207 <                    }
1208 <                    while (i != size && modCount == expectedModCount) {
1209 <                        consumer.accept((E) elementData[offset + (i++)]);
1201 >                    if (i < size) {
1202 >                        final Object[] es = root.elementData;
1203 >                        if (offset + i >= es.length)
1204 >                            throw new ConcurrentModificationException();
1205 >                        for (; i < size && modCount == expectedModCount; i++)
1206 >                            action.accept(elementAt(es, offset + i));
1207 >                        // update once at end to reduce heap write traffic
1208 >                        cursor = i;
1209 >                        lastRet = i - 1;
1210 >                        checkForComodification();
1211                      }
1180                    // update once at end of iteration to reduce heap write traffic
1181                    lastRet = cursor = i;
1182                    checkForComodification();
1212                  }
1213  
1214                  public int nextIndex() {
# Line 1269 | Line 1298 | public class ArrayList<E> extends Abstra
1298          public Spliterator<E> spliterator() {
1299              checkForComodification();
1300  
1301 <            // ArrayListSpliterator is not used because late-binding logic
1302 <            // is different here
1274 <            return new Spliterator<>() {
1301 >            // ArrayListSpliterator not used here due to late-binding
1302 >            return new Spliterator<E>() {
1303                  private int index = offset; // current index, modified on advance/split
1304                  private int fence = -1; // -1 until used; then one past last index
1305                  private int expectedModCount; // initialized when fence set
# Line 1285 | Line 1313 | public class ArrayList<E> extends Abstra
1313                      return hi;
1314                  }
1315  
1316 <                public ArrayListSpliterator<E> trySplit() {
1316 >                public ArrayList<E>.ArrayListSpliterator trySplit() {
1317                      int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
1318 <                    // ArrayListSpliterator could be used here as the source is already bound
1318 >                    // ArrayListSpliterator can be used here as the source is already bound
1319                      return (lo >= mid) ? null : // divide range in half unless too small
1320 <                        new ArrayListSpliterator<>(root, lo, index = mid,
1293 <                                                   expectedModCount);
1320 >                        root.new ArrayListSpliterator(lo, index = mid, expectedModCount);
1321                  }
1322  
1323                  public boolean tryAdvance(Consumer<? super E> action) {
# Line 1332 | Line 1359 | public class ArrayList<E> extends Abstra
1359                  }
1360  
1361                  public long estimateSize() {
1362 <                    return (long) (getFence() - index);
1362 >                    return getFence() - index;
1363                  }
1364  
1365                  public int characteristics() {
# Line 1342 | Line 1369 | public class ArrayList<E> extends Abstra
1369          }
1370      }
1371  
1372 +    /**
1373 +     * @throws NullPointerException {@inheritDoc}
1374 +     */
1375      @Override
1376      public void forEach(Consumer<? super E> action) {
1377          Objects.requireNonNull(action);
1378          final int expectedModCount = modCount;
1379 <        @SuppressWarnings("unchecked")
1350 <        final E[] elementData = (E[]) this.elementData;
1379 >        final Object[] es = elementData;
1380          final int size = this.size;
1381 <        for (int i=0; modCount == expectedModCount && i < size; i++) {
1382 <            action.accept(elementData[i]);
1383 <        }
1355 <        if (modCount != expectedModCount) {
1381 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1382 >            action.accept(elementAt(es, i));
1383 >        if (modCount != expectedModCount)
1384              throw new ConcurrentModificationException();
1357        }
1385      }
1386  
1387      /**
# Line 1372 | Line 1399 | public class ArrayList<E> extends Abstra
1399       */
1400      @Override
1401      public Spliterator<E> spliterator() {
1402 <        return new ArrayListSpliterator<>(this, 0, -1, 0);
1402 >        return new ArrayListSpliterator(0, -1, 0);
1403      }
1404  
1405      /** Index-based split-by-two, lazily initialized Spliterator */
1406 <    static final class ArrayListSpliterator<E> implements Spliterator<E> {
1406 >    final class ArrayListSpliterator implements Spliterator<E> {
1407  
1408          /*
1409           * If ArrayLists were immutable, or structurally immutable (no
# Line 1410 | Line 1437 | public class ArrayList<E> extends Abstra
1437           * these streamlinings.
1438           */
1439  
1413        private final ArrayList<E> list;
1440          private int index; // current index, modified on advance/split
1441          private int fence; // -1 until used; then one past last index
1442          private int expectedModCount; // initialized when fence set
1443  
1444 <        /** Create new spliterator covering the given  range */
1445 <        ArrayListSpliterator(ArrayList<E> list, int origin, int fence,
1420 <                             int expectedModCount) {
1421 <            this.list = list; // OK if null unless traversed
1444 >        /** Creates new spliterator covering the given range. */
1445 >        ArrayListSpliterator(int origin, int fence, int expectedModCount) {
1446              this.index = origin;
1447              this.fence = fence;
1448              this.expectedModCount = expectedModCount;
# Line 1426 | Line 1450 | public class ArrayList<E> extends Abstra
1450  
1451          private int getFence() { // initialize fence to size on first use
1452              int hi; // (a specialized variant appears in method forEach)
1429            ArrayList<E> lst;
1453              if ((hi = fence) < 0) {
1454 <                if ((lst = list) == null)
1455 <                    hi = fence = 0;
1433 <                else {
1434 <                    expectedModCount = lst.modCount;
1435 <                    hi = fence = lst.size;
1436 <                }
1454 >                expectedModCount = modCount;
1455 >                hi = fence = size;
1456              }
1457              return hi;
1458          }
1459  
1460 <        public ArrayListSpliterator<E> trySplit() {
1460 >        public ArrayListSpliterator trySplit() {
1461              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
1462              return (lo >= mid) ? null : // divide range in half unless too small
1463 <                new ArrayListSpliterator<>(list, lo, index = mid,
1445 <                                           expectedModCount);
1463 >                new ArrayListSpliterator(lo, index = mid, expectedModCount);
1464          }
1465  
1466          public boolean tryAdvance(Consumer<? super E> action) {
# Line 1451 | Line 1469 | public class ArrayList<E> extends Abstra
1469              int hi = getFence(), i = index;
1470              if (i < hi) {
1471                  index = i + 1;
1472 <                @SuppressWarnings("unchecked") E e = (E)list.elementData[i];
1472 >                @SuppressWarnings("unchecked") E e = (E)elementData[i];
1473                  action.accept(e);
1474 <                if (list.modCount != expectedModCount)
1474 >                if (modCount != expectedModCount)
1475                      throw new ConcurrentModificationException();
1476                  return true;
1477              }
# Line 1462 | Line 1480 | public class ArrayList<E> extends Abstra
1480  
1481          public void forEachRemaining(Consumer<? super E> action) {
1482              int i, hi, mc; // hoist accesses and checks from loop
1483 <            ArrayList<E> lst; Object[] a;
1483 >            Object[] a;
1484              if (action == null)
1485                  throw new NullPointerException();
1486 <            if ((lst = list) != null && (a = lst.elementData) != null) {
1486 >            if ((a = elementData) != null) {
1487                  if ((hi = fence) < 0) {
1488 <                    mc = lst.modCount;
1489 <                    hi = lst.size;
1488 >                    mc = modCount;
1489 >                    hi = size;
1490                  }
1491                  else
1492                      mc = expectedModCount;
# Line 1477 | Line 1495 | public class ArrayList<E> extends Abstra
1495                          @SuppressWarnings("unchecked") E e = (E) a[i];
1496                          action.accept(e);
1497                      }
1498 <                    if (lst.modCount == mc)
1498 >                    if (modCount == mc)
1499                          return;
1500                  }
1501              }
# Line 1485 | Line 1503 | public class ArrayList<E> extends Abstra
1503          }
1504  
1505          public long estimateSize() {
1506 <            return (long) (getFence() - index);
1506 >            return getFence() - index;
1507          }
1508  
1509          public int characteristics() {
# Line 1493 | Line 1511 | public class ArrayList<E> extends Abstra
1511          }
1512      }
1513  
1514 <    @SuppressWarnings("unchecked")
1514 >    // A tiny bit set implementation
1515 >
1516 >    private static long[] nBits(int n) {
1517 >        return new long[((n - 1) >> 6) + 1];
1518 >    }
1519 >    private static void setBit(long[] bits, int i) {
1520 >        bits[i >> 6] |= 1L << i;
1521 >    }
1522 >    private static boolean isClear(long[] bits, int i) {
1523 >        return (bits[i >> 6] & (1L << i)) == 0;
1524 >    }
1525 >
1526 >    /**
1527 >     * @throws NullPointerException {@inheritDoc}
1528 >     */
1529      @Override
1530      public boolean removeIf(Predicate<? super E> filter) {
1531 +        return removeIf(filter, 0, size);
1532 +    }
1533 +
1534 +    /**
1535 +     * Removes all elements satisfying the given predicate, from index
1536 +     * i (inclusive) to index end (exclusive).
1537 +     */
1538 +    boolean removeIf(Predicate<? super E> filter, int i, final int end) {
1539          Objects.requireNonNull(filter);
1540          int expectedModCount = modCount;
1541          final Object[] es = elementData;
1502        final int size = this.size;
1503        final boolean modified;
1504        int r;
1542          // Optimize for initial run of survivors
1543 <        for (r = 0; r < size; r++)
1544 <            if (filter.test((E) es[r]))
1545 <                break;
1546 <        if (modified = (r < size)) {
1543 >        for (; i < end && !filter.test(elementAt(es, i)); i++)
1544 >            ;
1545 >        // Tolerate predicates that reentrantly access the collection for
1546 >        // read (but writers still get CME), so traverse once to find
1547 >        // elements to delete, a second pass to physically expunge.
1548 >        if (i < end) {
1549 >            final int beg = i;
1550 >            final long[] deathRow = nBits(end - beg);
1551 >            deathRow[0] = 1L;   // set bit 0
1552 >            for (i = beg + 1; i < end; i++)
1553 >                if (filter.test(elementAt(es, i)))
1554 >                    setBit(deathRow, i - beg);
1555 >            if (modCount != expectedModCount)
1556 >                throw new ConcurrentModificationException();
1557              expectedModCount++;
1558              modCount++;
1559 <            int w = r++;
1560 <            try {
1561 <                for (E e; r < size; r++)
1562 <                    if (!filter.test(e = (E) es[r]))
1563 <                        es[w++] = e;
1564 <            } catch (Throwable ex) {
1565 <                // copy remaining elements
1566 <                System.arraycopy(es, r, es, w, size - r);
1567 <                w += size - r;
1568 <                throw ex;
1569 <            } finally {
1570 <                Arrays.fill(es, (this.size = w), size, null);
1524 <            }
1559 >            int w = beg;
1560 >            for (i = beg; i < end; i++)
1561 >                if (isClear(deathRow, i - beg))
1562 >                    es[w++] = es[i];
1563 >            shiftTailOverGap(es, w, end);
1564 >            // checkInvariants();
1565 >            return true;
1566 >        } else {
1567 >            if (modCount != expectedModCount)
1568 >                throw new ConcurrentModificationException();
1569 >            // checkInvariants();
1570 >            return false;
1571          }
1526        if (modCount != expectedModCount)
1527            throw new ConcurrentModificationException();
1528        return modified;
1572      }
1573  
1574      @Override
1532    @SuppressWarnings("unchecked")
1575      public void replaceAll(UnaryOperator<E> operator) {
1576          Objects.requireNonNull(operator);
1577          final int expectedModCount = modCount;
1578 +        final Object[] es = elementData;
1579          final int size = this.size;
1580 <        for (int i=0; modCount == expectedModCount && i < size; i++) {
1581 <            elementData[i] = operator.apply((E) elementData[i]);
1582 <        }
1540 <        if (modCount != expectedModCount) {
1580 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1581 >            es[i] = operator.apply(elementAt(es, i));
1582 >        if (modCount != expectedModCount)
1583              throw new ConcurrentModificationException();
1542        }
1584          modCount++;
1585 +        // checkInvariants();
1586      }
1587  
1588      @Override
# Line 1548 | Line 1590 | public class ArrayList<E> extends Abstra
1590      public void sort(Comparator<? super E> c) {
1591          final int expectedModCount = modCount;
1592          Arrays.sort((E[]) elementData, 0, size, c);
1593 <        if (modCount != expectedModCount) {
1593 >        if (modCount != expectedModCount)
1594              throw new ConcurrentModificationException();
1553        }
1595          modCount++;
1596 +        // checkInvariants();
1597 +    }
1598 +
1599 +    void checkInvariants() {
1600 +        // assert size >= 0;
1601 +        // assert size == elementData.length || elementData[size] == null;
1602      }
1603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines