/* An instance of this class represents a non-empty list of items. ** ** Author: R. McCloskey, November 2019 */ public class RecursiveListNonEmpty implements RecursiveList { // instance variables // ------------------ private T head; private RecursiveList tail; // constructors // ------------ public RecursiveListNonEmpty(T item) { this(item, RecursiveListEmpty.emptyListFactory()); } //this(item, new RecursiveListEmpty()); } public RecursiveListNonEmpty(T item, RecursiveList list) { head = item; tail = list; } public boolean isEmpty() { return false; } public T headOf() { return head; } public RecursiveList tailOf() { return tail; } public String toString() { return "< " + headOf() + " " + tailOf().toString() + ">"; } public RecursiveList cons(T item) { return new RecursiveListNonEmpty(item, this); } public RecursiveList emptyList() { return RecursiveListEmpty.emptyListFactory(); //return new RecursiveListEmpty(); } }