mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -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
|
||||
public E element() {
|
||||
return null;
|
||||
if (firstEntry == null) {
|
||||
throw new TNoSuchElementException();
|
||||
}
|
||||
return firstEntry.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -273,12 +276,12 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
|
|||
|
||||
@Override
|
||||
public void push(E e) {
|
||||
add(e);
|
||||
addFirst(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E pop() {
|
||||
return removeLast();
|
||||
return removeFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -214,4 +214,13 @@ public class LinkedListTest {
|
|||
assertEquals(4, list.size());
|
||||
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