/* * Adds the objects in the specified Collection to this {@code LinkedList}. * * @param collection * the collection of objects. * @return {@code true} if this {@code LinkedList} is modified, * {@code false} otherwise. */ public override bool addAll(Collection <E> collection) { int adding = collection.size(); if (adding == 0) { return(false); } dotnet.util.wrapper.EnumerableIterator <E> elements = new dotnet.util.wrapper.EnumerableIterator <E>( (collection == this) ? new ArrayList <E>(collection) : collection ); Link <E> previous = voidLink.previous; foreach (E e in elements) { Link <E> newLink = new Link <E>(e, previous, null); previous.next = newLink; previous = newLink; } previous.next = voidLink; voidLink.previous = previous; sizeJ += adding; modCount++; return(true); }
/* * Inserts the objects in the specified collection at the specified location * in this {@code LinkedList}. 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 {@code true} if this {@code LinkedList} is modified, * {@code false} otherwise. * @throws ClassCastException * if the class of an object is inappropriate for this list. * @throws IllegalArgumentException * if an object cannot be added to this list. * @throws IndexOutOfBoundsException * if {@code location < 0 || > size()} */ public override bool addAll(int location, Collection <E> collection) { if (location < 0 || location > sizeJ) { throw new java.lang.IndexOutOfBoundsException(); } int adding = collection.size(); if (adding == 0) { return(false); } dotnet.util.wrapper.EnumerableIterator <E> elements = new dotnet.util.wrapper.EnumerableIterator <E>( (collection == this) ? new ArrayList <E>(collection) : collection ); Link <E> previous = voidLink; if (location < (sizeJ / 2)) { for (int i = 0; i < location; i++) { previous = previous.next; } } else { for (int i = sizeJ; i >= location; i--) { previous = previous.previous; } } Link <E> next = previous.next; foreach (E e in elements) { Link <E> newLink = new Link <E>(e, previous, null); previous.next = newLink; previous = newLink; } previous.next = next; next.previous = previous; sizeJ += adding; modCount++; return(true); }