package clist; class NonEmptyNode extends ANode { private Object _data; private CList _clockwiseTail; private CList _counterClockwiseTail; NonEmptyNode(Object data, CList counterClockwiseOwner, CList clockwiseOwner) { _data = data; clockwiseOwner.setCounterClockwiseHead(this); counterClockwiseOwner.setClockwiseHead(this); } Object getData() { return _data; } void setData(Object data) { _data = data; } // --- Clockwise Operations: ---------------------------------------------- CList getRestClockwise() { return _clockwiseTail; } void setRestClockwise(CList tail) { _clockwiseTail = tail; } void insertFrontClockwise(Object data, CList owner) { new NonEmptyNode(data, owner, new CList(EmptyNode.Singleton, this)); } Object removeFrontClockwise(CList owner) { if (owner == _clockwiseTail) { /* * This node is the only node in the list. After its * removal the list should be empty. */ owner.setClockwiseHead(EmptyNode.Singleton); owner.setCounterClockwiseHead(EmptyNode.Singleton); } else { /* * Remove the clockwise ANode and CList objects. Make the * owner reference the next clockwise ANode, and make that * ANode reference the owner. */ owner.setClockwiseHead(_clockwiseTail.getClockwiseHead()); /* * Make the clockwise CList an empty list because there * could be a reference to it. */ _clockwiseTail.setClockwiseHead(EmptyNode.Singleton); _clockwiseTail.setCounterClockwiseHead(EmptyNode.Singleton); } return _data; } // --- Counter Clockwise Operations: -------------------------------------- CList getRestCounterClockwise() { return _counterClockwiseTail; } void setRestCounterClockwise(CList tail) { _counterClockwiseTail = tail; } void insertFrontCounterClockwise(Object data, CList owner) { new NonEmptyNode(data, new CList(this, EmptyNode.Singleton), owner); } Object removeFrontCounterClockwise(CList owner) { if (owner == _counterClockwiseTail) { /* * This node is the only node in the list. After its * removal the list should be empty. */ owner.setClockwiseHead(EmptyNode.Singleton); owner.setCounterClockwiseHead(EmptyNode.Singleton); } else { /* * Remove the counter-clockwise ANode and CList objects. * Make the owner reference the next counter-clockwise * ANode, and make that ANode reference the owner. */ owner.setCounterClockwiseHead( _counterClockwiseTail.getCounterClockwiseHead()); /* * Make the counter-clockwise CList an empty list. */ _counterClockwiseTail.setClockwiseHead(EmptyNode.Singleton); _counterClockwiseTail.setCounterClockwiseHead(EmptyNode.Singleton); } return _data; } // ------------------------------------------------------------------------ Object execute(IAlgo algo, Object input, CList owner) { return algo.nonEmptyCase(owner, input); } }