/** * Empty recursive list of objects. * @author Jeff Raab */ public class EmptyRecursiveList implements IList { /** Singleton empty list. */ public static final EmptyRecursiveList EMPTY = new EmptyRecursiveList(); /** Constructs an empty list. */ private EmptyRecursiveList() {} /** Returns the first position in this. */ public Position first() { throw new RuntimeException("List is empty"); } /** Returns the last position in this. */ public Position last() { throw new RuntimeException("List is empty"); } /** * Returns the position in this * that comes before the given position. * @param aPosition position for which previous position is desired */ public Position before(Position aPosition) { throw new RuntimeException("Position not in list"); } /** * Returns the position in this * that comes before the given position. * @param aPosition position for which previous position is desired */ public Position after(Position aPosition) { throw new RuntimeException("Position not in list"); } /** * Returns whether or not the given position is first in this. * @param aPosition position to test */ public boolean isFirst(Position aPosition) { return false; } /** * Returns whether or not the given position is last in this. * @param aPosition position to test */ public boolean isLast(Position aPosition) { return false; } /** * Inserts the given object at the beginning of this, * increasing the size of this by 1. * @param anObject object to insert */ public IList insertFirst(Object anObject) { return new RecursiveList(anObject); } /** * Inserts the given object at the end of this, * increasing the size of this by 1. * @param anObject object to insert */ public IList insertLast(Object anObject) { return new RecursiveList(anObject); } /** * Inserts the given object before the given position in this, * increasing the size of this by 1. * @param aPosition position to insert before * @param anObject object to insert */ public IList insertBefore(Position aPosition, Object anObject) { throw new RuntimeException("Position not in list"); } /** * Inserts the given object after the given position in this, * increasing the size of this by 1. * @param aPosition position to insert before * @param anObject object to insert */ public IList insertAfter(Position aPosition, Object anObject) { throw new RuntimeException("Position not in list"); } /** Removes and returns the first element of this. */ public IList removeFirst() { throw new RuntimeException("List is empty"); } /** Removes and returns the last element of this. */ public IList removeLast() { throw new RuntimeException("List is empty"); } /** * Removes the given position from this and returns its element. * @param aPosition position to remove */ public IList remove(Position aPosition) { throw new RuntimeException("Position not in list"); } /** * Returns the element in the given position of this * and replaces it with the given object. * @param aPosition position of element to replace * @param anObject object to store in the given position */ public Object replaceElement(Position aPosition, Object anObject) { throw new RuntimeException("Position not in list"); } /** Returns the size of this. */ public int size() { return 0; } /** Returns whether or not this is empty. */ public boolean isEmpty() { return true; } }