mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
class: fix LinkedList.offer method adding item incorrectly at the beginning
Fix #772
This commit is contained in:
parent
0b2d1428fb
commit
4a81615749
|
@ -95,17 +95,7 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public boolean offer(E e) {
|
||||
Entry<E> entry = new Entry<>();
|
||||
entry.item = e;
|
||||
entry.next = firstEntry;
|
||||
if (firstEntry != null) {
|
||||
firstEntry.previous = entry;
|
||||
} else {
|
||||
lastEntry = entry;
|
||||
}
|
||||
firstEntry = entry;
|
||||
++modCount;
|
||||
++size;
|
||||
addLast(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -149,7 +139,17 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public void addFirst(E e) {
|
||||
offer(e);
|
||||
Entry<E> entry = new Entry<>();
|
||||
entry.item = e;
|
||||
entry.next = firstEntry;
|
||||
if (firstEntry != null) {
|
||||
firstEntry.previous = entry;
|
||||
} else {
|
||||
lastEntry = entry;
|
||||
}
|
||||
firstEntry = entry;
|
||||
++modCount;
|
||||
++size;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -308,4 +308,13 @@ public class LinkedListTest {
|
|||
lit.add("x");
|
||||
assertEquals(List.of("d", "x", "a"), list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void offerOrder() {
|
||||
var list = new LinkedList<String>();
|
||||
list.offer("1");
|
||||
list.offer("2");
|
||||
assertEquals("1", list.getFirst());
|
||||
assertEquals("2", list.getLast());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user