(int location, Collection<? extends E> collection)
| 330 | /// |
| 331 | /// - `IndexOutOfBoundsException`: if `location size()` |
| 332 | @Override |
| 333 | public boolean addAll(int location, Collection<? extends E> collection) { |
| 334 | if (location < 0 || location > size) { |
| 335 | throw new IndexOutOfBoundsException(); |
| 336 | } |
| 337 | int adding = collection.size(); |
| 338 | if (adding == 0) { |
| 339 | return false; |
| 340 | } |
| 341 | Collection<? extends E> elements = (collection == this) ? |
| 342 | new ArrayList<E>(collection) : collection; |
| 343 | |
| 344 | Link<E> previous = voidLink; |
| 345 | if (location < (size / 2)) { |
| 346 | for (int i = 0; i < location; i++) { |
| 347 | previous = previous.next; |
| 348 | } |
| 349 | } else { |
| 350 | for (int i = size; i >= location; i--) { |
| 351 | previous = previous.previous; |
| 352 | } |
| 353 | } |
| 354 | Link<E> next = previous.next; |
| 355 | Iterator it = elements.iterator(); |
| 356 | while(it.hasNext()) { |
| 357 | Link<E> newLink = new Link<E>((E)it.next(), previous, null); |
| 358 | previous.next = newLink; |
| 359 | previous = newLink; |
| 360 | } |
| 361 | previous.next = next; |
| 362 | next.previous = previous; |
| 363 | size += adding; |
| 364 | modCount++; |
| 365 | return true; |
| 366 | } |
| 367 | |
| 368 | /// Adds the objects in the specified Collection to this `LinkedList`. |
| 369 | /// |
no test coverage detected