Testat Sammlung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1011 B

package solution;
import java.util.LinkedList;
import java.util.List;
import testat.IAction;
import testat.ISimpleStack;
public class SimpleStack<T> implements ISimpleStack<T> {
private List<T> list;
public SimpleStack() {
super();
list = new LinkedList<T>();
}
@Override
public int push(T t) {
if (t != null) {
if (list.contains(t)) {
list.remove(t);
}
list.add(t);
return list.size();
}
return 0;
}
@Override
public T pop() {
if (list.size() == 0) {
return null;
}
return list.remove(list.size() - 1);
}
@Override
public T remove(int i) {
return list.remove(i);
}
@Override
public int size() {
return list.size();
}
@Override
public boolean contains(Object o) {
return list.contains(o);
}
@Override
public T get(int i) {
return list.get(i);
}
@Override
public void forAll(IAction<T> action) {
if (action != null) {
list.forEach(t -> action.execute(t));
}
}
}