// file: EmptyList.java // author: Robert Keller // purpose: EmptyList class of Poly package package Poly; import java.io.*; import java.lang.*; /** * EmptyList is the sub-class of List containing the empty list. **/ public class EmptyList extends List { /** * EmptyList() constructs an empty list **/ public EmptyList() {} // constructor /** * isEmpty() tells whether the List is empty. **/ public boolean isEmpty() { return true; } /** * nonEmpty() tells whether the List is non-empty **/ public boolean nonEmpty() { return false; } /** * first() returns the first element of a non-empty List. * @exception EmptyListException Can't take first of an empty List. * **/ public Object first() throws EmptyListException { throw new EmptyListException("first of empty List"); } /** * rest() returns the rest of a non-empty List. * @exception EmptyListException Can't take rest of an empty List. **/ public List rest() throws EmptyListException { throw new EmptyListException("rest of empty List"); } public NonEmptyList getNonEmpty() throws EmptyListException { throw new EmptyListException("getNonEmpty of empty List"); } public String toString() { return "()"; } } // class EmptyList