@Test(expected = IndexOutOfBoundsException.class) public void testAddOnHugeTooLargeIndex_ExpectException() { list.add(0, 1); list.add(44444, 2); fail("Exception was expected"); }
@Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; }
SimpleArrayList extends AbstractList<E> implements List<E> { @Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; } }
SimpleArrayList extends AbstractList<E> implements List<E> { @Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; }  }
SimpleArrayList extends AbstractList<E> implements List<E> { @Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; }  @Override int size(); @SuppressWarnings("unchecked") @Override E get(int index); @Override E set(int index, E element); @Override void add(int index, E element); @Override E remove(int index); long getCounter(); }
SimpleArrayList extends AbstractList<E> implements List<E> { @Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; }  @Override int size(); @SuppressWarnings("unchecked") @Override E get(int index); @Override E set(int index, E element); @Override void add(int index, E element); @Override E remove(int index); long getCounter();  }