Inserts the objects in the specified collection at the specified location in this List. The objects are added in the order they are returned from the collection's iterator. @param location the index at which to insert. @param collection the collection of objects. @return {@cod
(int location, Collection<? extends E> collection)
| 171 | * when {@code location < 0 || > size()} |
| 172 | */ |
| 173 | @Override |
| 174 | public boolean addAll(int location, Collection<? extends E> collection) { |
| 175 | if (location < 0 || location > size) { |
| 176 | throw new IndexOutOfBoundsException( |
| 177 | // luni.0A=Index: {0}, Size: {1} |
| 178 | Messages.getString("luni.0A", //$NON-NLS-1$ |
| 179 | Integer.valueOf(location), |
| 180 | Integer.valueOf(size))); |
| 181 | } |
| 182 | |
| 183 | Object[] dumparray = collection.toArray(); |
| 184 | int growSize = dumparray.length; |
| 185 | // REVIEW: Why do this check here rather than check |
| 186 | // collection.size() earlier? RI behaviour? |
| 187 | if (growSize == 0) { |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | if (location == 0) { |
| 192 | growAtFront(growSize); |
| 193 | firstIndex -= growSize; |
| 194 | } else if (location == size) { |
| 195 | if (firstIndex + size > array.length - growSize) { |
| 196 | growAtEnd(growSize); |
| 197 | } |
| 198 | } else { // must be case: (0 < location && location < size) |
| 199 | if (array.length - size < growSize) { |
| 200 | growForInsert(location, growSize); |
| 201 | } else if (firstIndex + size > array.length - growSize |
| 202 | || (firstIndex > 0 && location < size / 2)) { |
| 203 | int newFirst = firstIndex - growSize; |
| 204 | if (newFirst < 0) { |
| 205 | int index = location + firstIndex; |
| 206 | System.arraycopy(array, index, array, index - newFirst, |
| 207 | size - location); |
| 208 | newFirst = 0; |
| 209 | } |
| 210 | System.arraycopy(array, firstIndex, array, newFirst, location); |
| 211 | firstIndex = newFirst; |
| 212 | } else { |
| 213 | int index = location + firstIndex; |
| 214 | System.arraycopy(array, index, array, index + growSize, size |
| 215 | - location); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | System.arraycopy(dumparray, 0, this.array, location + firstIndex, |
| 220 | growSize); |
| 221 | size += growSize; |
| 222 | modCount++; |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Adds the objects in the specified collection to this {@code ArrayList}. |
nothing calls this directly
no test coverage detected