package list.dl; import java.util.NoSuchElementException; import list.dl.algo.IAlgoLeft; import list.dl.algo.IAlgoRight; import list.dl.algo.GetLeftEnd; import list.dl.algo.GetRightEnd; /** * Node containing data and links to left and right. * @author DXN * @version 3.2 * @since 10/17/00 */ class DataNode extends ANode { private Object _dat; /** @SBGen Variable (,theLeft,,64) */ private DLList _leftList; /** @SBGen Variable (,theRight,,64) */ private DLList _rightList; DataNode (Object dat, DLList leftList, DLList rightList) { _dat = dat; leftList.setRightNode (this); rightList.setLeftNode (this); } Object getFirst (DLList owner) { return _dat; } /** * Pre: this node is the left node of owner. */ DLList getLeftRest (DLList owner) { return _leftList; } /** * Pre: this node is the right node of owner. */ DLList getRightRest (DLList owner) { return _rightList; } /** * Sets the left owner link. * @param dllist */ void setLeftOwner (DLList dlList) { _leftList = dlList; } /** * Sets the right owner link. * @param dllist */ void setRightOwner (DLList dlList) { _rightList = dlList; } /**
      Pre: this node is the left node of ownerList.
      Post: this node is the left node of ownerList.getLeftRest ().
      
* @param dat * @param ownerList */ void insertLeftFront (Object dat, DLList ownerList) { new DataNode (dat, new DLList (this, RightEndNode.Singleton), ownerList); /* "Old" style details: DLList newList = new DLList (); DataNode newNode = new DataNode (dat, newList, ownerList); newList.setRightNode (newNode); newList.setLeftNode (this); _rightList = newList; ownerList.setLeftNode (newNode); */ } /**
      Pre: this node is the right node of ownerList.
      Post: this node is the right node of owner.getRightRest ().
      
* @param dat * @param ownerList */ void insertRightFront (Object dat, DLList ownerList) { new DataNode (dat, ownerList, new DLList (LeftEndNode.Singleton, this)); } /**
      Pre: this node is the left node of owner.  X is _leftList.leftNode ().
      Post: owner.leftNode () is X;  _leftList is empty.
      
*/ Object remLeftFront (DLList owner) { owner.setLeftNode (_leftList.getLeftNode()); _leftList.setRightNode (RightEndNode.Singleton); _leftList.setLeftNode (LeftEndNode.Singleton); //_leftList's invariant re-established. return _dat; } /**
      Pre: this node is the right node of owner.  X is _rightList.rightNode ().
      Post: owner.rightNode () is X;  _rightList is empty.
      
*/ Object remRightFront (DLList owner) { owner.setRightNode (_rightList.getRightNode()); _rightList.setRightNode (RightEndNode.Singleton); _rightList.setLeftNode (LeftEndNode.Singleton); //_rightList's invariant re-established. return _dat; } /** * @param dat */ void setFirst (Object dat, DLList owner) { _dat = dat; } /** * Pre: this node is the left node of owner. * @param dlList */ void setLeftRest (DLList dlList, DLList owner) { _leftList.setRightNode (RightEndNode.Singleton);//_leftList's invariant re-established. DLList rightEnd = (DLList)dlList.executeRight (GetRightEnd.Singleton, null); rightEnd.setRightNode (this); } /** * Pre: this node is the right node of owner. * @param dlList */ void setRightRest (DLList dlList, DLList owner) { _rightList.setLeftNode (LeftEndNode.Singleton); //_rightList's invariant re-established. DLList leftEnd = (DLList)dlList.executeLeft (GetLeftEnd.Singleton, null); leftEnd.setLeftNode (this); } /** * Pre: this node is the left node of ownerList. * @param algo * @param input * @param owner */ Object executeLeft (IAlgoLeft algo, Object input, DLList owner) { return algo.dataNodeCase (owner, input); } /** * Pre: this node is the right node of ownerList. * @param algo * @param input * @param owner */ Object executeRight (IAlgoRight algo, Object input, DLList owner) { return algo.dataNodeCase (owner, input); } }