classlib: fix for positioned addAll in sequential lists (#824)

This commit is contained in:
Ivan Hetman 2023-10-16 14:41:15 +03:00 committed by GitHub
parent 5bc398415d
commit 1900852cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -72,7 +72,6 @@ public abstract class TAbstractSequentialList<E> extends TAbstractList<E> {
boolean added = false; boolean added = false;
for (TIterator<? extends E> srcIter = c.iterator(); srcIter.hasNext();) { for (TIterator<? extends E> srcIter = c.iterator(); srcIter.hasNext();) {
iter.add(srcIter.next()); iter.add(srcIter.next());
iter.next();
added = true; added = true;
} }
return added; return added;

View File

@ -317,4 +317,11 @@ public class LinkedListTest {
assertEquals("1", list.getFirst()); assertEquals("1", list.getFirst());
assertEquals("2", list.getLast()); assertEquals("2", list.getLast());
} }
@Test
public void testAddAllPositioned() {
LinkedList<String> ll = new LinkedList<>(Arrays.asList("a", "b", "c", "d"));
ll.addAll(2, new LinkedList<>(ll));
assertArrayEquals(new String[] {"a", "b", "a", "b", "c", "d", "c", "d"}, ll.toArray());
}
} }