mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix LinkedList.push and .element methods
This commit is contained in:
parent
a4e41fc6be
commit
4082c6389a
|
@ -140,7 +140,10 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public E element() {
|
public E element() {
|
||||||
return null;
|
if (firstEntry == null) {
|
||||||
|
throw new TNoSuchElementException();
|
||||||
|
}
|
||||||
|
return firstEntry.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -273,12 +276,12 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(E e) {
|
public void push(E e) {
|
||||||
add(e);
|
addFirst(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public E pop() {
|
public E pop() {
|
||||||
return removeLast();
|
return removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -214,4 +214,13 @@ public class LinkedListTest {
|
||||||
assertEquals(4, list.size());
|
assertEquals(4, list.size());
|
||||||
assertArrayEquals(new String[] { "1", "2", "3", "1" }, list.toArray(new String[0]));
|
assertArrayEquals(new String[] { "1", "2", "3", "1" }, list.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pushes() {
|
||||||
|
LinkedList<String> list = new LinkedList<>();
|
||||||
|
list.push("foo");
|
||||||
|
assertEquals("foo", list.peek());
|
||||||
|
list.push("bar");
|
||||||
|
assertEquals("bar", list.peek());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user