package list.dl; import java.util.NoSuchElementException; import list.dl.algo.IAlgoLeft; import list.dl.algo.IAlgoRight; /** * Singleton pattern representing the left end node of a doubly-linked list. * @author DXN * @version 3.2 * @since 10/17/00 */ class LeftEndNode extends ANode { final static LeftEndNode Singleton = new LeftEndNode (); private LeftEndNode () { } Object getFirst (DLList owner) // Pre: this node is the left node of owner. { throw new NoSuchElementException ("LeftEndNode.getLeftFirst: Left end has no data."); } DLList getLeftRest (DLList owner) // Pre: this node is the left node of owner. { throw new NoSuchElementException ("LeftEndNode.getLeftRest: Left end has no left tail."); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param owner * @return */ Object getRightFirst (DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.getRightFirst ()"); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param owner * @return */ DLList getRightRest(DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.getRightRest ()"); } /** * Throws IllegalStateException. * @param dllist */ void setLeftOwner (DLList dllist) { throw new IllegalStateException ("Should never call LeftEnd.setLeftOwner ()"); } /** * Does nothing. * @param dllist */ void setRightOwner (DLList dllist) { } /**
   Pre: this node is the left node of owner.
   Post: this node is the left node of owner.getLeftRest ().
   
* @param dat */ void insertLeftFront (Object dat, DLList owner) { new DataNode (dat, new DLList (), owner); /* Old style: DLList newList = new DLList (); DataNode newNode = new DataNode (dat, newList, owner); newList.setRightNode (newNode); owner.setLeftNode (newNode); */ } Object remLeftFront (DLList owner) // Pre: this node is the left node of owner. { throw new NoSuchElementException ("LeftEndNode.remLeftFront: Left end has no data."); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param dat the element to be inserted to the right front of the owner. * @param owner the DLList that holds this ANode. */ void insertRightFront (Object dat, DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.insertRightFront ()"); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param owner the DLList that holds this ANode. * @return */ Object remRightFront (DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.remRightFront ()"); } /** * Throws NoSuchElementException. * @param dat */ void setFirst (Object dat, DLList owner) { throw new NoSuchElementException ("LeftEndNode.setFirst: Left end has no data."); } /** * Throws NoSuchElementException. * @param dllist */ void setLeftRest (DLList dllist, DLList owner) // Pre: this node is the left node of owner. { throw new NoSuchElementException ("LeftEndNode.setLeftRest: Left end has no left tail."); } /** * @param algo * @param input * @param ownerList */ Object executeLeft (IAlgoLeft algo, Object input, DLList owner) // Pre: this node is the left node of ownerList. { return algo.leftEndCase (owner, input); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param dllist the new tail that is to replace the current one. * @param owner the DLList that holds this ANode. */ void setRightRest (DLList dllist, DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.setRightRest ()"); } /** * Throws IllegalStateException. Can never be a the right node of a DLList * @param algo * @param input * @param owner * @return */ Object executeRight (IAlgoRight algo, Object input, DLList owner) { throw new IllegalStateException ("Should never call LeftEnd.executeRight ()"); } }