Fix updating size in LinkedList.remove (fix #226).

This commit is contained in:
Alexey Andreev 2016-11-04 13:28:34 +03:00
parent 2a3b0cd597
commit 8c3f071f88
2 changed files with 4 additions and 3 deletions

View File

@ -348,7 +348,6 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
} else if (currentEntry == nextEntry) {
nextEntry = hasPrevious() ? prevEntry.next : null;
}
--size;
version = modCount;
currentEntry = null;
}

View File

@ -106,6 +106,7 @@ public class LinkedListTest {
assertEquals(2, iter.nextIndex());
assertEquals("a", iter.next());
assertArrayEquals(new String[] { "1", "2", "a", "b" }, list.toArray(new String[0]));
assertEquals(4, list.size());
}
@Test
@ -138,6 +139,7 @@ public class LinkedListTest {
iter.remove();
assertEquals(1, iter.nextIndex());
assertEquals("3", iter.next());
assertEquals(4, list.size());
}
@Test(expected = IllegalStateException.class)
@ -195,7 +197,7 @@ public class LinkedListTest {
}
@Test
public void removesFirstOccurence() {
public void removesFirstOccurrence() {
LinkedList<String> list = new LinkedList<>();
list.addAll(Arrays.asList("1", "2", "3", "1", "2"));
assertFalse(list.removeFirstOccurrence("*"));
@ -205,7 +207,7 @@ public class LinkedListTest {
}
@Test
public void removesLastOccurence() {
public void removesLastOccurrence() {
LinkedList<String> list = new LinkedList<>();
list.addAll(Arrays.asList("1", "2", "3", "1", "2"));
assertFalse(list.removeLastOccurrence("*"));