package listadt; import java.util.function.Function; /** * This is the implementation of a generic list. Specifically it implements * the listadt.ListADT interface */ public class ListADTImpl implements ListADT { private GenericListADTNode head; public ListADTImpl() { head = new GenericEmptyNode(); } //a private constructor that is used internally (see map) private ListADTImpl(GenericListADTNode head) { this.head = head; } @Override public void addFront(T b) { head = head.addFront(b); } @Override public void addBack(T b) { head = head.addBack(b); } @Override public void add(int index, T b) { head = head.add(index,b); } @Override public int getSize() { return head.count(); } @Override public void remove(T b) { head = head.remove(b); } @Override public T get(int index) throws IllegalArgumentException{ if ((index>=0) && (index ListADT map(Function converter) { return new ListADTImpl(head.map(converter)); } @Override public String toString() { return "("+head.toString()+")"; } }