package list; /** * Represents the empty list. * Implemented as a singleton. * * @author Dung X. Nguyen * @version 1.0 * @since 09/10/00 * @Custom Copyright 2000 -All rights reserved */ class EmptyList extends AList { /** @SBGen Variable (singleton pattern,,,0) */ public final static EmptyList Singleton = new EmptyList (); /* * NOTE: the constructor is private so that no client can * instantiate an EmptyList. */ private EmptyList () { } /** * Throws an IllegalArgumentException. * @return does not return. */ public Object getFirst () { throw new IllegalArgumentException ("Empty List has no data."); } /** * Throws an IllegalArgumentException * @return does not return. */ public AList getRest () { throw new IllegalArgumentException ("Empty List has no tail."); } public String toString() { return "()"; } /** * Terminates the String representation of the original AList * by returning ")". */ protected String toStringHelp() { return ")"; } /** * Returns 0. */ public int length() { return 0; } /** * Returns 0. */ public int getLength() { return 0; } /** * Returns the accumulated length, since this is the end of the list. */ protected int getLengthHelp(int acc) { return acc; } /** * Returns the empty AList itself since the clone of the empty list * is the empty list. */ public AList makeClone() { return this; } /** * Throws an IllegalArgumentException. */ public Object nthElement(int n) { throw new IllegalArgumentException ("nthElement: Index out of range."); } /** * Throws an IllegalArgumentException. */ public Object lastElement() { throw new IllegalArgumentException ("lastElement: Empty list has no element."); } /** * Returns the input element that is being passed down, * since this is the end of the original list. * @return previous */ protected Object lastElementHelp(Object previous) { return previous; } /** * Returns the empty list itself since this is the longest list * we can return. */ public AList firstElements(int num_elts) { if (num_elts < 0) { throw new IllegalArgumentException ("firstElements: Meaningless to ask for a negative number (" + num_elts + ") of elements."); } if (num_elts > 0) { throw new IllegalArgumentException ("firstElements: Empty list has no elements."); } return this; } /** * Returns the empty AList itself since the reverse of the empty list * is the empty list. */ public AList reverse() { return this; } /** * Returns the reversed list so far, since this is the end of the * original list. * @return stack */ protected AList reverseHelp(AList stack) { return stack; } /** * Returns the list to be concatenated with. */ public AList append(AList list2) { return list2; } }