package list.dl; import java.util.NoSuchElementException; import list.dl.algo.IAlgoLeft; import list.dl.algo.IAlgoRight; /** * Singleton pattern representing the right end node of a doubly-linked list. * @author DXN * @version 3.2 * @since 10/17/00 */ class RightEndNode extends ANode { final static RightEndNode Singleton = new RightEndNode (); private RightEndNode () { } /** * Throws IllegalStateException. * @param owner * @return */ Object getFirst (DLList owner) { throw new IllegalStateException ("Should never call RightEnd.getFirst ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param owner * @return */ DLList getLeftRest (DLList owner) { throw new IllegalStateException ("Should never call RightEnd.getLeftRest ()"); } /** * Throws IllegalStateException. * @param dat the element that is to replace the current first element on the left/right of the owner list. * @param owner the DLList that holds this ANode. */ void setFirst (Object dat, DLList owner) { throw new IllegalStateException ("Should never call RightEnd.setFirst ()"); } /** * Throws IllegalStateException. Can never be a the left 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 setLeftRest (DLList dllist, DLList owner) { throw new IllegalStateException ("Should never call RightEnd.setLeftRest ()"); } DLList getRightRest (DLList owner) // Pre: this node is the right node of owner. { throw new NoSuchElementException ("RightEndNode.getRightRest: right end has no right tail."); } /** * Does nothing. The right node is dessigned a singleton to be shared. There is no left link. * @param dllist */ void setLeftOwner (DLList dllist) { } /** * Throws IllegalStateException. * @param dllist */ void setRightOwner (DLList dllist) { throw new IllegalStateException ("Should never call RightEnd.setRightOwner ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param dat the element to be inserted to the left front of the owner. * @param owner the DLList that holds this ANode. */ void insertLeftFront (Object dat, DLList owner) { throw new IllegalStateException ("Should never call RightEnd.insertLeftFirst ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param owner the DLList that holds this ANode. * @return */ Object remLeftFront (DLList owner) { throw new IllegalStateException ("Should never call RightEnd.remLeftFront ()"); } /** * @param dat */ void insertRightFront (Object dat, DLList owner) // Pre: this node is the right node of owner. // Post: this node is the right node of owner.getRightRest (). { new DataNode (dat, owner, new DLList ()); /* old style: DLList newList = new DLList (); DataNode newNode = new DataNode (dat, owner, newList); newList.setLeftNode (newNode); owner.setRightNode (newNode); */ } Object remRightFront (DLList owner) // Pre: this node is the right node of owner. { throw new NoSuchElementException ("RightEndNode.remRightFront: Right end has no data."); } /** * Throws new NoSuchElementException. * @param dat */ void setRightFirst (Object dat, DLList owner) // Pre: this node is the right node of owner. { throw new NoSuchElementException ("RightEndNode.setRightFirst: Right end has no data."); } /** * Throws new NoSuchElementException. * @param dllist */ void setRightRest (DLList dllist, DLList owner) // Pre: this node is the right node of owner. { throw new NoSuchElementException ("RightEndNode.setRightRest: Right end has no right tail."); } /** * @param algo * @param input * @param owner */ Object executeRight (IAlgoRight algo, Object input, DLList owner) // Pre: this node is the right node of ownerList. { return algo.rightEndCase (owner, input); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param algo * @param input * @param owner * @return */ Object executeLeft (IAlgoLeft algo, Object input, DLList owner) { throw new IllegalStateException ("Should never call RightEnd.executeLeft ()"); } }