package list.dl; import java.util.NoSuchElementException; import list.dl.algo.IAlgoLeft; import list.dl.algo.IAlgoRight; class RightEndNode extends ANode { final public static RightEndNode Singleton = new RightEndNode (); private RightEndNode () { } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param parent * @return */ Object leftFirst (DLList parent) { throw new IllegalStateException ("Should never call RightEnd.leftFirst ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param parent * @return */ DLList leftRest (DLList parent) { throw new IllegalStateException ("Should never call RightEnd.leftRest ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param dat the element that is to replace the current first element on the left of the parent list. * @param parent the DLList that holds this ANode. */ void setLeftFirst (Object dat, DLList parent) { throw new IllegalStateException ("Should never call RightEnd.setLeftFirst ()"); } /** * 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 parent the DLList that holds this ANode. */ void setLeftRest (DLList dllist, DLList parent) { throw new IllegalStateException ("Should never call RightEnd.setLeftRest ()"); } Object rightFirst (DLList parent) // Pre: this node is the right node of parent. { throw new NoSuchElementException ("RightEndNode.rightFirst: right end has no data."); } DLList rightRest (DLList parent) // Pre: this node is the right node of parent. { throw new NoSuchElementException ("RightEndNode.rightRest: 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 setLeftParent (DLList dllist) { } /** * Throws IllegalStateException. * @param dllist */ void setRightParent (DLList dllist) { throw new IllegalStateException ("Should never call RightEnd.setRightParent ()"); } /** * 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 parent. * @param parent the DLList that holds this ANode. */ void insertLeftFront (Object dat, DLList parent) { throw new IllegalStateException ("Should never call RightEnd.insertLeftFirst ()"); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param parent the DLList that holds this ANode. * @return */ Object remLeftFirst (DLList parent) { throw new IllegalStateException ("Should never call RightEnd.remLeftFirst ()"); } /** * @param dat */ void insertRightFront (Object dat, DLList parent) // Pre: this node is the right node of parent. // Post: this node is the right node of parent.rightRest (). { new DataNode (dat, parent, new DLList ()); /* old style: DLList newList = new DLList (); DataNode newNode = new DataNode (dat, parent, newList); newList.setLeftNode (newNode); parent.setRightNode (newNode); */ } Object remRightFirst (DLList parent) // Pre: this node is the right node of parent. { throw new NoSuchElementException ("RightEndNode.remRightFirst: Right end has no data."); } /** * Throws new NoSuchElementException. * @param dat */ void setRightFirst (Object dat, DLList parent) // Pre: this node is the right node of parent. { throw new NoSuchElementException ("RightEndNode.setRightFirst: Right end has no data."); } /** * Throws new NoSuchElementException. * @param dllist */ void setRightRest (DLList dllist, DLList parent) // Pre: this node is the right node of parent. { throw new NoSuchElementException ("RightEndNode.setRightRest: Right end has no right tail."); } /** * @param algo * @param inputParam * @param parentList */ Object executeRight (IAlgoRight algo, Object inputParam, DLList parentList) // Pre: this node is the right node of parentList. { return algo.rightEndCase (parentList, inputParam); } /** * Throws IllegalStateException. Can never be a the left node of a DLList * @param algo * @param input * @param parentList * @return */ Object executeLeft (IAlgoLeft algo, Object input, DLList parentList) { throw new IllegalStateException ("Should never call RightEnd.executeLeft ()"); } }