Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/ArrayList.java
          +++ new/src/share/classes/java/util/ArrayList.java
↓ open down ↓ 112 lines elided ↑ open up ↑
 113  113      /**
 114  114       * The size of the ArrayList (the number of elements it contains).
 115  115       *
 116  116       * @serial
 117  117       */
 118  118      private int size;
 119  119  
 120  120      /**
 121  121       * Constructs an empty list with the specified initial capacity.
 122  122       *
 123      -     * @param   initialCapacity   the initial capacity of the list
 124      -     * @exception IllegalArgumentException if the specified initial capacity
 125      -     *            is negative
      123 +     * @param  initialCapacity  the initial capacity of the list
      124 +     * @throws IllegalArgumentException if the specified initial capacity
      125 +     *         is negative
 126  126       */
 127  127      public ArrayList(int initialCapacity) {
 128  128          super();
 129  129          if (initialCapacity < 0)
 130  130              throw new IllegalArgumentException("Illegal Capacity: "+
 131  131                                                 initialCapacity);
 132  132          this.elementData = new Object[initialCapacity];
 133  133      }
 134  134  
 135  135      /**
↓ open down ↓ 30 lines elided ↑ open up ↑
 166  166          if (size < oldCapacity) {
 167  167              elementData = Arrays.copyOf(elementData, size);
 168  168          }
 169  169      }
 170  170  
 171  171      /**
 172  172       * Increases the capacity of this <tt>ArrayList</tt> instance, if
 173  173       * necessary, to ensure that it can hold at least the number of elements
 174  174       * specified by the minimum capacity argument.
 175  175       *
 176      -     * @param minCapacity the desired minimum capacity
      176 +     * @param   minCapacity   the desired minimum capacity
 177  177       */
 178  178      public void ensureCapacity(int minCapacity) {
 179  179          if (minCapacity > 0)
 180  180              ensureCapacityInternal(minCapacity);
 181  181      }
 182  182  
 183  183      private void ensureCapacityInternal(int minCapacity) {
 184  184          modCount++;
 185  185          // overflow-conscious code
 186  186          if (minCapacity - elementData.length > 0)
↓ open down ↓ 17 lines elided ↑ open up ↑
 204  204      private void grow(int minCapacity) {
 205  205          // overflow-conscious code
 206  206          int oldCapacity = elementData.length;
 207  207          int newCapacity = oldCapacity + (oldCapacity >> 1);
 208  208          if (newCapacity - minCapacity < 0)
 209  209              newCapacity = minCapacity;
 210  210          if (newCapacity - MAX_ARRAY_SIZE > 0)
 211  211              newCapacity = hugeCapacity(minCapacity);
 212  212          // minCapacity is usually close to size, so this is a win:
 213  213          elementData = Arrays.copyOf(elementData, newCapacity);
 214      -    }
      214 +        }
 215  215  
 216  216      private static int hugeCapacity(int minCapacity) {
 217  217          if (minCapacity < 0) // overflow
 218  218              throw new OutOfMemoryError();
 219  219          return (minCapacity > MAX_ARRAY_SIZE) ?
 220  220              Integer.MAX_VALUE :
 221  221              MAX_ARRAY_SIZE;
 222  222      }
 223  223  
 224  224      /**
↓ open down ↓ 904 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX