Name: Anonymous 2011-11-30 10:39
http://www.docjar.com/html/api/java/util/ArrayList.java.html
What's the point of having a range check if it only checks if the index is >= to the size and not if it's < 0. This seems stupid and a waste of a method call.
ensureCapacity is never called, yet they have it in the class.
BLOAT
374 /**
375 * Returns the element at the specified position in this list.
376 *
377 * @param index index of the element to return
378 * @return the element at the specified position in this list
379 * @throws IndexOutOfBoundsException {@inheritDoc}
380 */
381 public E get(int index) {
382 rangeCheck(index);
383
384 return elementData(index);
385 }
596 /**
597 * Checks if the given index is in range. If not, throws an appropriate
598 * runtime exception. This method does *not* check if the index is
599 * negative: It is always used immediately prior to an array access,
600 * which throws an ArrayIndexOutOfBoundsException if index is negative.
601 */
602 private void rangeCheck(int index) {
603 if (index >= size)
604 throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
605 }What's the point of having a range check if it only checks if the index is >= to the size and not if it's < 0. This seems stupid and a waste of a method call.
171 /**
172 * Increases the capacity of this <tt>ArrayList</tt> instance, if
173 * necessary, to ensure that it can hold at least the number of elements
174 * specified by the minimum capacity argument.
175 *
176 * @param minCapacity the desired minimum capacity
177 */
178 public void ensureCapacity(int minCapacity) {
179 if (minCapacity > 0)
180 ensureCapacityInternal(minCapacity);
181 }
182
183 private void ensureCapacityInternal(int minCapacity) {
184 modCount++;
185 // overflow-conscious code
186 if (minCapacity - elementData.length > 0)
187 grow(minCapacity);
188 }ensureCapacity is never called, yet they have it in the class.
BLOAT