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.39 by jsr166, Sun Nov 13 02:10:09 2016 UTC vs.
Revision 1.55 by jsr166, Mon Jan 8 21:51:07 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 28 | Line 28 | package java.util;
28   import java.util.function.Consumer;
29   import java.util.function.Predicate;
30   import java.util.function.UnaryOperator;
31 + import jdk.internal.misc.SharedSecrets;
32  
33   /**
34   * Resizable-array implementation of the {@code List} interface.  Implements
# Line 91 | Line 92 | import java.util.function.UnaryOperator;
92   * should be used only to detect bugs.</i>
93   *
94   * <p>This class is a member of the
95 < * <a href="{@docRoot}/../technotes/guides/collections/index.html">
95 > * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
96   * Java Collections Framework</a>.
97   *
98   * @param <E> the type of elements in this list
# Line 501 | Line 502 | public class ArrayList<E> extends Abstra
502                           s - index);
503          elementData[index] = element;
504          size = s + 1;
505 +        // checkInvariants();
506      }
507  
508      /**
# Line 514 | Line 516 | public class ArrayList<E> extends Abstra
516       */
517      public E remove(int index) {
518          Objects.checkIndex(index, size);
519 +        final Object[] es = elementData;
520  
521 <        modCount++;
522 <        E oldValue = elementData(index);
520 <
521 <        int numMoved = size - index - 1;
522 <        if (numMoved > 0)
523 <            System.arraycopy(elementData, index+1, elementData, index,
524 <                             numMoved);
525 <        elementData[--size] = null; // clear to let GC do its work
521 >        @SuppressWarnings("unchecked") E oldValue = (E) es[index];
522 >        fastRemove(es, index);
523  
524 +        // checkInvariants();
525          return oldValue;
526      }
527  
# Line 541 | Line 539 | public class ArrayList<E> extends Abstra
539       * @return {@code true} if this list contained the specified element
540       */
541      public boolean remove(Object o) {
542 <        if (o == null) {
543 <            for (int index = 0; index < size; index++)
544 <                if (elementData[index] == null) {
545 <                    fastRemove(index);
546 <                    return true;
547 <                }
548 <        } else {
549 <            for (int index = 0; index < size; index++)
550 <                if (o.equals(elementData[index])) {
551 <                    fastRemove(index);
552 <                    return true;
553 <                }
542 >        final Object[] es = elementData;
543 >        final int size = this.size;
544 >        int i = 0;
545 >        found: {
546 >            if (o == null) {
547 >                for (; i < size; i++)
548 >                    if (es[i] == null)
549 >                        break found;
550 >            } else {
551 >                for (; i < size; i++)
552 >                    if (o.equals(es[i]))
553 >                        break found;
554 >            }
555 >            return false;
556          }
557 <        return false;
557 >        fastRemove(es, i);
558 >        return true;
559      }
560  
561 <    /*
561 >    /**
562       * Private remove method that skips bounds checking and does not
563       * return the value removed.
564       */
565 <    private void fastRemove(int index) {
565 >    private void fastRemove(Object[] es, int i) {
566          modCount++;
567 <        int numMoved = size - index - 1;
568 <        if (numMoved > 0)
569 <            System.arraycopy(elementData, index+1, elementData, index,
570 <                             numMoved);
570 <        elementData[--size] = null; // clear to let GC do its work
567 >        final int newSize;
568 >        if ((newSize = size - 1) > i)
569 >            System.arraycopy(es, i + 1, es, i, newSize - i);
570 >        es[size = newSize] = null;
571      }
572  
573      /**
# Line 576 | Line 576 | public class ArrayList<E> extends Abstra
576       */
577      public void clear() {
578          modCount++;
579 <
580 <        // clear to let GC do its work
581 <        for (int i = 0; i < size; i++)
582 <            elementData[i] = null;
583 <
584 <        size = 0;
579 >        final Object[] es = elementData;
580 >        for (int to = size, i = size = 0; i < to; i++)
581 >            es[i] = null;
582      }
583  
584      /**
# Line 609 | Line 606 | public class ArrayList<E> extends Abstra
606              elementData = grow(s + numNew);
607          System.arraycopy(a, 0, elementData, s, numNew);
608          size = s + numNew;
609 +        // checkInvariants();
610          return true;
611      }
612  
# Line 647 | Line 645 | public class ArrayList<E> extends Abstra
645                               numMoved);
646          System.arraycopy(a, 0, elementData, index, numNew);
647          size = s + numNew;
648 +        // checkInvariants();
649          return true;
650      }
651  
# Line 669 | Line 668 | public class ArrayList<E> extends Abstra
668                      outOfBoundsMsg(fromIndex, toIndex));
669          }
670          modCount++;
671 <        int numMoved = size - toIndex;
672 <        System.arraycopy(elementData, toIndex, elementData, fromIndex,
673 <                         numMoved);
674 <
675 <        // clear to let GC do its work
676 <        int newSize = size - (toIndex-fromIndex);
677 <        for (int i = newSize; i < size; i++) {
678 <            elementData[i] = null;
679 <        }
681 <        size = newSize;
671 >        shiftTailOverGap(elementData, fromIndex, toIndex);
672 >        // checkInvariants();
673 >    }
674 >
675 >    /** Erases the gap from lo to hi, by sliding down following elements. */
676 >    private void shiftTailOverGap(Object[] es, int lo, int hi) {
677 >        System.arraycopy(es, hi, es, lo, size - hi);
678 >        for (int to = size, i = (size -= hi - lo); i < to; i++)
679 >            es[i] = null;
680      }
681  
682      /**
# Line 721 | Line 719 | public class ArrayList<E> extends Abstra
719       * @see Collection#contains(Object)
720       */
721      public boolean removeAll(Collection<?> c) {
722 <        return batchRemove(c, false);
722 >        return batchRemove(c, false, 0, size);
723      }
724  
725      /**
# Line 741 | Line 739 | public class ArrayList<E> extends Abstra
739       * @see Collection#contains(Object)
740       */
741      public boolean retainAll(Collection<?> c) {
742 <        return batchRemove(c, true);
742 >        return batchRemove(c, true, 0, size);
743      }
744  
745 <    private boolean batchRemove(Collection<?> c, boolean complement) {
745 >    boolean batchRemove(Collection<?> c, boolean complement,
746 >                        final int from, final int end) {
747          Objects.requireNonNull(c);
748          final Object[] es = elementData;
750        final int end = size;
751        final boolean modified;
749          int r;
750          // Optimize for initial run of survivors
751 <        for (r = 0; r < end && c.contains(es[r]) == complement; r++)
752 <            ;
753 <        if (modified = (r < end)) {
754 <            int w = r++;
755 <            try {
756 <                for (Object e; r < end; r++)
757 <                    if (c.contains(e = es[r]) == complement)
758 <                        es[w++] = e;
759 <            } catch (Throwable ex) {
760 <                // Preserve behavioral compatibility with AbstractCollection,
761 <                // even if c.contains() throws.
762 <                System.arraycopy(es, r, es, w, end - r);
763 <                w += end - r;
764 <                throw ex;
765 <            } finally {
766 <                modCount += end - w;
767 <                Arrays.fill(es, size = w, end, null);
768 <            }
751 >        for (r = from;; r++) {
752 >            if (r == end)
753 >                return false;
754 >            if (c.contains(es[r]) != complement)
755 >                break;
756 >        }
757 >        int w = r++;
758 >        try {
759 >            for (Object e; r < end; r++)
760 >                if (c.contains(e = es[r]) == complement)
761 >                    es[w++] = e;
762 >        } catch (Throwable ex) {
763 >            // Preserve behavioral compatibility with AbstractCollection,
764 >            // even if c.contains() throws.
765 >            System.arraycopy(es, r, es, w, end - r);
766 >            w += end - r;
767 >            throw ex;
768 >        } finally {
769 >            modCount += end - w;
770 >            shiftTailOverGap(es, w, end);
771          }
772 <        return modified;
772 >        // checkInvariants();
773 >        return true;
774      }
775  
776      /**
777 <     * Save the state of the {@code ArrayList} instance to a stream (that
778 <     * is, serialize it).
777 >     * Saves the state of the {@code ArrayList} instance to a stream
778 >     * (that is, serializes it).
779       *
780 +     * @param s the stream
781 +     * @throws java.io.IOException if an I/O error occurs
782       * @serialData The length of the array backing the {@code ArrayList}
783       *             instance is emitted (int), followed by all of its elements
784       *             (each an {@code Object}) in the proper order.
785       */
786      private void writeObject(java.io.ObjectOutputStream s)
787 <        throws java.io.IOException{
787 >        throws java.io.IOException {
788          // Write out element count, and any hidden stuff
789          int expectedModCount = modCount;
790          s.defaultWriteObject();
791  
792 <        // Write out size as capacity for behavioural compatibility with clone()
792 >        // Write out size as capacity for behavioral compatibility with clone()
793          s.writeInt(size);
794  
795          // Write out all elements in the proper order.
# Line 801 | Line 803 | public class ArrayList<E> extends Abstra
803      }
804  
805      /**
806 <     * Reconstitute the {@code ArrayList} instance from a stream (that is,
807 <     * deserialize it).
806 >     * Reconstitutes the {@code ArrayList} instance from a stream (that is,
807 >     * deserializes it).
808 >     * @param s the stream
809 >     * @throws ClassNotFoundException if the class of a serialized object
810 >     *         could not be found
811 >     * @throws java.io.IOException if an I/O error occurs
812       */
813      private void readObject(java.io.ObjectInputStream s)
814          throws java.io.IOException, ClassNotFoundException {
# Line 815 | Line 821 | public class ArrayList<E> extends Abstra
821  
822          if (size > 0) {
823              // like clone(), allocate array based upon size not capacity
824 +            SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
825              Object[] elements = new Object[size];
826  
827              // Read in all elements in the proper order.
# Line 914 | Line 921 | public class ArrayList<E> extends Abstra
921          }
922  
923          @Override
924 <        @SuppressWarnings("unchecked")
925 <        public void forEachRemaining(Consumer<? super E> consumer) {
919 <            Objects.requireNonNull(consumer);
924 >        public void forEachRemaining(Consumer<? super E> action) {
925 >            Objects.requireNonNull(action);
926              final int size = ArrayList.this.size;
927              int i = cursor;
928 <            if (i >= size) {
929 <                return;
930 <            }
931 <            final Object[] elementData = ArrayList.this.elementData;
932 <            if (i >= elementData.length) {
933 <                throw new ConcurrentModificationException();
934 <            }
935 <            while (i != size && modCount == expectedModCount) {
936 <                consumer.accept((E) elementData[i++]);
928 >            if (i < size) {
929 >                final Object[] es = elementData;
930 >                if (i >= es.length)
931 >                    throw new ConcurrentModificationException();
932 >                for (; i < size && modCount == expectedModCount; i++)
933 >                    action.accept(elementAt(es, i));
934 >                // update once at end to reduce heap write traffic
935 >                cursor = i;
936 >                lastRet = i - 1;
937 >                checkForComodification();
938              }
932            // update once at end of iteration to reduce heap write traffic
933            cursor = i;
934            lastRet = i - 1;
935            checkForComodification();
939          }
940  
941          final void checkForComodification() {
# Line 1119 | Line 1122 | public class ArrayList<E> extends Abstra
1122              return true;
1123          }
1124  
1125 +        public boolean removeAll(Collection<?> c) {
1126 +            return batchRemove(c, false);
1127 +        }
1128 +
1129 +        public boolean retainAll(Collection<?> c) {
1130 +            return batchRemove(c, true);
1131 +        }
1132 +
1133 +        private boolean batchRemove(Collection<?> c, boolean complement) {
1134 +            checkForComodification();
1135 +            int oldSize = root.size;
1136 +            boolean modified =
1137 +                root.batchRemove(c, complement, offset, offset + size);
1138 +            if (modified)
1139 +                updateSizeAndModCount(root.size - oldSize);
1140 +            return modified;
1141 +        }
1142 +
1143 +        public boolean removeIf(Predicate<? super E> filter) {
1144 +            checkForComodification();
1145 +            int oldSize = root.size;
1146 +            boolean modified = root.removeIf(filter, offset, offset + size);
1147 +            if (modified)
1148 +                updateSizeAndModCount(root.size - oldSize);
1149 +            return modified;
1150 +        }
1151 +
1152          public Iterator<E> iterator() {
1153              return listIterator();
1154          }
# Line 1166 | Line 1196 | public class ArrayList<E> extends Abstra
1196                      return (E) elementData[offset + (lastRet = i)];
1197                  }
1198  
1199 <                @SuppressWarnings("unchecked")
1200 <                public void forEachRemaining(Consumer<? super E> consumer) {
1171 <                    Objects.requireNonNull(consumer);
1199 >                public void forEachRemaining(Consumer<? super E> action) {
1200 >                    Objects.requireNonNull(action);
1201                      final int size = SubList.this.size;
1202                      int i = cursor;
1203 <                    if (i >= size) {
1204 <                        return;
1205 <                    }
1206 <                    final Object[] elementData = root.elementData;
1207 <                    if (offset + i >= elementData.length) {
1208 <                        throw new ConcurrentModificationException();
1209 <                    }
1210 <                    while (i != size && modCount == expectedModCount) {
1211 <                        consumer.accept((E) elementData[offset + (i++)]);
1203 >                    if (i < size) {
1204 >                        final Object[] es = root.elementData;
1205 >                        if (offset + i >= es.length)
1206 >                            throw new ConcurrentModificationException();
1207 >                        for (; i < size && modCount == expectedModCount; i++)
1208 >                            action.accept(elementAt(es, offset + i));
1209 >                        // update once at end to reduce heap write traffic
1210 >                        cursor = i;
1211 >                        lastRet = i - 1;
1212 >                        checkForComodification();
1213                      }
1184                    // update once at end of iteration to reduce heap write traffic
1185                    lastRet = cursor = i;
1186                    checkForComodification();
1214                  }
1215  
1216                  public int nextIndex() {
# Line 1273 | Line 1300 | public class ArrayList<E> extends Abstra
1300          public Spliterator<E> spliterator() {
1301              checkForComodification();
1302  
1303 <            // ArrayListSpliterator is not used because late-binding logic
1304 <            // is different here
1278 <            return new Spliterator<>() {
1303 >            // ArrayListSpliterator not used here due to late-binding
1304 >            return new Spliterator<E>() {
1305                  private int index = offset; // current index, modified on advance/split
1306                  private int fence = -1; // -1 until used; then one past last index
1307                  private int expectedModCount; // initialized when fence set
# Line 1289 | Line 1315 | public class ArrayList<E> extends Abstra
1315                      return hi;
1316                  }
1317  
1318 <                public ArrayListSpliterator<E> trySplit() {
1318 >                public ArrayList<E>.ArrayListSpliterator trySplit() {
1319                      int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
1320 <                    // ArrayListSpliterator could be used here as the source is already bound
1320 >                    // ArrayListSpliterator can be used here as the source is already bound
1321                      return (lo >= mid) ? null : // divide range in half unless too small
1322 <                        new ArrayListSpliterator<>(root, lo, index = mid,
1297 <                                                   expectedModCount);
1322 >                        root.new ArrayListSpliterator(lo, index = mid, expectedModCount);
1323                  }
1324  
1325                  public boolean tryAdvance(Consumer<? super E> action) {
# Line 1336 | Line 1361 | public class ArrayList<E> extends Abstra
1361                  }
1362  
1363                  public long estimateSize() {
1364 <                    return (long) (getFence() - index);
1364 >                    return getFence() - index;
1365                  }
1366  
1367                  public int characteristics() {
# Line 1346 | Line 1371 | public class ArrayList<E> extends Abstra
1371          }
1372      }
1373  
1374 +    /**
1375 +     * @throws NullPointerException {@inheritDoc}
1376 +     */
1377      @Override
1378      public void forEach(Consumer<? super E> action) {
1379          Objects.requireNonNull(action);
1380          final int expectedModCount = modCount;
1381          final Object[] es = elementData;
1382          final int size = this.size;
1383 <        for (int i = 0; modCount == expectedModCount && i < size; i++) {
1383 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1384              action.accept(elementAt(es, i));
1385 <        }
1358 <        if (modCount != expectedModCount) {
1385 >        if (modCount != expectedModCount)
1386              throw new ConcurrentModificationException();
1360        }
1387      }
1388  
1389      /**
# Line 1375 | Line 1401 | public class ArrayList<E> extends Abstra
1401       */
1402      @Override
1403      public Spliterator<E> spliterator() {
1404 <        return new ArrayListSpliterator<>(this, 0, -1, 0);
1404 >        return new ArrayListSpliterator(0, -1, 0);
1405      }
1406  
1407      /** Index-based split-by-two, lazily initialized Spliterator */
1408 <    static final class ArrayListSpliterator<E> implements Spliterator<E> {
1408 >    final class ArrayListSpliterator implements Spliterator<E> {
1409  
1410          /*
1411           * If ArrayLists were immutable, or structurally immutable (no
# Line 1413 | Line 1439 | public class ArrayList<E> extends Abstra
1439           * these streamlinings.
1440           */
1441  
1416        private final ArrayList<E> list;
1442          private int index; // current index, modified on advance/split
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 */
1447 <        ArrayListSpliterator(ArrayList<E> list, int origin, int fence,
1423 <                             int expectedModCount) {
1424 <            this.list = list; // OK if null unless traversed
1446 >        /** Creates new spliterator covering the given range. */
1447 >        ArrayListSpliterator(int origin, int fence, int expectedModCount) {
1448              this.index = origin;
1449              this.fence = fence;
1450              this.expectedModCount = expectedModCount;
# Line 1429 | Line 1452 | public class ArrayList<E> extends Abstra
1452  
1453          private int getFence() { // initialize fence to size on first use
1454              int hi; // (a specialized variant appears in method forEach)
1432            ArrayList<E> lst;
1455              if ((hi = fence) < 0) {
1456 <                if ((lst = list) == null)
1457 <                    hi = fence = 0;
1436 <                else {
1437 <                    expectedModCount = lst.modCount;
1438 <                    hi = fence = lst.size;
1439 <                }
1456 >                expectedModCount = modCount;
1457 >                hi = fence = size;
1458              }
1459              return hi;
1460          }
1461  
1462 <        public ArrayListSpliterator<E> trySplit() {
1462 >        public ArrayListSpliterator trySplit() {
1463              int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
1464              return (lo >= mid) ? null : // divide range in half unless too small
1465 <                new ArrayListSpliterator<>(list, lo, index = mid,
1448 <                                           expectedModCount);
1465 >                new ArrayListSpliterator(lo, index = mid, expectedModCount);
1466          }
1467  
1468          public boolean tryAdvance(Consumer<? super E> action) {
# Line 1454 | Line 1471 | public class ArrayList<E> extends Abstra
1471              int hi = getFence(), i = index;
1472              if (i < hi) {
1473                  index = i + 1;
1474 <                @SuppressWarnings("unchecked") E e = (E)list.elementData[i];
1474 >                @SuppressWarnings("unchecked") E e = (E)elementData[i];
1475                  action.accept(e);
1476 <                if (list.modCount != expectedModCount)
1476 >                if (modCount != expectedModCount)
1477                      throw new ConcurrentModificationException();
1478                  return true;
1479              }
# Line 1465 | Line 1482 | public class ArrayList<E> extends Abstra
1482  
1483          public void forEachRemaining(Consumer<? super E> action) {
1484              int i, hi, mc; // hoist accesses and checks from loop
1485 <            ArrayList<E> lst; Object[] a;
1485 >            Object[] a;
1486              if (action == null)
1487                  throw new NullPointerException();
1488 <            if ((lst = list) != null && (a = lst.elementData) != null) {
1488 >            if ((a = elementData) != null) {
1489                  if ((hi = fence) < 0) {
1490 <                    mc = lst.modCount;
1491 <                    hi = lst.size;
1490 >                    mc = modCount;
1491 >                    hi = size;
1492                  }
1493                  else
1494                      mc = expectedModCount;
# Line 1480 | Line 1497 | public class ArrayList<E> extends Abstra
1497                          @SuppressWarnings("unchecked") E e = (E) a[i];
1498                          action.accept(e);
1499                      }
1500 <                    if (lst.modCount == mc)
1500 >                    if (modCount == mc)
1501                          return;
1502                  }
1503              }
# Line 1488 | Line 1505 | public class ArrayList<E> extends Abstra
1505          }
1506  
1507          public long estimateSize() {
1508 <            return (long) (getFence() - index);
1508 >            return getFence() - index;
1509          }
1510  
1511          public int characteristics() {
# Line 1508 | Line 1525 | public class ArrayList<E> extends Abstra
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) {
1532 >    public boolean removeIf(Predicate<? super E> filter) {
1533 >        return removeIf(filter, 0, size);
1534 >    }
1535 >
1536 >    /**
1537 >     * Removes all elements satisfying the given predicate, from index
1538 >     * i (inclusive) to index end (exclusive).
1539 >     */
1540 >    boolean removeIf(Predicate<? super E> filter, int i, final int end) {
1541          Objects.requireNonNull(filter);
1542          int expectedModCount = modCount;
1543          final Object[] es = elementData;
1516        final int end = size;
1517        final boolean modified;
1518        int i;
1544          // Optimize for initial run of survivors
1545 <        for (i = 0; i < end && !filter.test(elementAt(es, i)); i++)
1545 >        for (; i < end && !filter.test(elementAt(es, i)); i++)
1546              ;
1547          // Tolerate predicates that reentrantly access the collection for
1548          // read (but writers still get CME), so traverse once to find
1549          // elements to delete, a second pass to physically expunge.
1550 <        if (modified = (i < end)) {
1526 <            expectedModCount++;
1527 <            modCount++;
1550 >        if (i < end) {
1551              final int beg = i;
1552              final long[] deathRow = nBits(end - beg);
1553              deathRow[0] = 1L;   // set bit 0
1554              for (i = beg + 1; i < end; i++)
1555                  if (filter.test(elementAt(es, i)))
1556                      setBit(deathRow, i - beg);
1557 +            if (modCount != expectedModCount)
1558 +                throw new ConcurrentModificationException();
1559 +            modCount++;
1560              int w = beg;
1561              for (i = beg; i < end; i++)
1562                  if (isClear(deathRow, i - beg))
1563                      es[w++] = es[i];
1564 <            Arrays.fill(es, size = w, end, null);
1564 >            shiftTailOverGap(es, w, end);
1565 >            // checkInvariants();
1566 >            return true;
1567 >        } else {
1568 >            if (modCount != expectedModCount)
1569 >                throw new ConcurrentModificationException();
1570 >            // checkInvariants();
1571 >            return false;
1572          }
1540        if (modCount != expectedModCount)
1541            throw new ConcurrentModificationException();
1542        return modified;
1573      }
1574  
1575      @Override
# Line 1548 | Line 1578 | public class ArrayList<E> extends Abstra
1578          final int expectedModCount = modCount;
1579          final Object[] es = elementData;
1580          final int size = this.size;
1581 <        for (int i=0; modCount == expectedModCount && i < size; i++) {
1581 >        for (int i = 0; modCount == expectedModCount && i < size; i++)
1582              es[i] = operator.apply(elementAt(es, i));
1583 <        }
1554 <        if (modCount != expectedModCount) {
1583 >        if (modCount != expectedModCount)
1584              throw new ConcurrentModificationException();
1556        }
1585          modCount++;
1586 +        // checkInvariants();
1587      }
1588  
1589      @Override
# Line 1562 | Line 1591 | public class ArrayList<E> extends Abstra
1591      public void sort(Comparator<? super E> c) {
1592          final int expectedModCount = modCount;
1593          Arrays.sort((E[]) elementData, 0, size, c);
1594 <        if (modCount != expectedModCount) {
1594 >        if (modCount != expectedModCount)
1595              throw new ConcurrentModificationException();
1567        }
1596          modCount++;
1597 +        // checkInvariants();
1598 +    }
1599 +
1600 +    void checkInvariants() {
1601 +        // assert size >= 0;
1602 +        // assert size == elementData.length || elementData[size] == null;
1603      }
1604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines