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.54 by jsr166, Sun Oct 22 17:44:03 2017 UTC vs.
Revision 1.59 by jsr166, Sun May 6 01:14:25 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 1997, 2018, 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 1122 | Line 1122 | public class ArrayList<E> extends Abstra
1122              return true;
1123          }
1124  
1125 +        public void replaceAll(UnaryOperator<E> operator) {
1126 +            root.replaceAllRange(operator, offset, offset + size);
1127 +        }
1128 +
1129          public boolean removeAll(Collection<?> c) {
1130              return batchRemove(c, false);
1131          }
# Line 1149 | Line 1153 | public class ArrayList<E> extends Abstra
1153              return modified;
1154          }
1155  
1156 +        public Object[] toArray() {
1157 +            checkForComodification();
1158 +            return Arrays.copyOfRange(root.elementData, offset, offset + size);
1159 +        }
1160 +
1161 +        @SuppressWarnings("unchecked")
1162 +        public <T> T[] toArray(T[] a) {
1163 +            checkForComodification();
1164 +            if (a.length < size)
1165 +                return (T[]) Arrays.copyOfRange(
1166 +                        root.elementData, offset, offset + size, a.getClass());
1167 +            System.arraycopy(root.elementData, offset, a, 0, size);
1168 +            if (a.length > size)
1169 +                a[size] = null;
1170 +            return a;
1171 +        }
1172 +
1173          public Iterator<E> iterator() {
1174              return listIterator();
1175          }
# Line 1556 | Line 1577 | public class ArrayList<E> extends Abstra
1577                      setBit(deathRow, i - beg);
1578              if (modCount != expectedModCount)
1579                  throw new ConcurrentModificationException();
1559            expectedModCount++;
1580              modCount++;
1581              int w = beg;
1582              for (i = beg; i < end; i++)
# Line 1575 | Line 1595 | public class ArrayList<E> extends Abstra
1595  
1596      @Override
1597      public void replaceAll(UnaryOperator<E> operator) {
1598 +        replaceAllRange(operator, 0, size);
1599 +    }
1600 +
1601 +    private void replaceAllRange(UnaryOperator<E> operator, int i, int end) {
1602          Objects.requireNonNull(operator);
1603          final int expectedModCount = modCount;
1604          final Object[] es = elementData;
1605 <        final int size = this.size;
1582 <        for (int i = 0; modCount == expectedModCount && i < size; i++)
1605 >        for (; modCount == expectedModCount && i < end; i++)
1606              es[i] = operator.apply(elementAt(es, i));
1607          if (modCount != expectedModCount)
1608              throw new ConcurrentModificationException();
1586        modCount++;
1609          // checkInvariants();
1610      }
1611  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines