Inserts the specified object into this ArrayList at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this ArrayList, the object is added at the end. @param location the index at w
(int location, E object)
| 101 | * when {@code location < 0 || > size()} |
| 102 | */ |
| 103 | @Override |
| 104 | public void add(int location, E object) { |
| 105 | if (location < 0 || location > size) { |
| 106 | throw new IndexOutOfBoundsException( |
| 107 | // luni.0A=Index: {0}, Size: {1} |
| 108 | Messages.getString("luni.0A", //$NON-NLS-1$ |
| 109 | Integer.valueOf(location), |
| 110 | Integer.valueOf(size))); |
| 111 | } |
| 112 | if (location == 0) { |
| 113 | if (firstIndex == 0) { |
| 114 | growAtFront(1); |
| 115 | } |
| 116 | array[--firstIndex] = object; |
| 117 | } else if (location == size) { |
| 118 | if (firstIndex + size == array.length) { |
| 119 | growAtEnd(1); |
| 120 | } |
| 121 | array[firstIndex + size] = object; |
| 122 | } else { // must be case: (0 < location && location < size) |
| 123 | if (size == array.length) { |
| 124 | growForInsert(location, 1); |
| 125 | } else if (firstIndex + size == array.length |
| 126 | || (firstIndex > 0 && location < size / 2)) { |
| 127 | System.arraycopy(array, firstIndex, array, --firstIndex, |
| 128 | location); |
| 129 | } else { |
| 130 | int index = location + firstIndex; |
| 131 | System.arraycopy(array, index, array, index + 1, size |
| 132 | - location); |
| 133 | } |
| 134 | array[location + firstIndex] = object; |
| 135 | } |
| 136 | |
| 137 | size++; |
| 138 | modCount++; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Adds the specified object at the end of this {@code ArrayList}. |
no test coverage detected