package clist; class DatNode extends ANode { private Object _dat; /** @SBGen Variable (,,,64) */ private CLList _clockwiseTail; /** @SBGen Variable (,,,64) */ private CLList _counterwiseTail; /** * When this DatNode is brought into existence, it is properly and completely wired to its * counter-clockwise owner and its clocwise owner. * @param dat * @param _clockwiseOwner * @param _counterwiseOwner */ DatNode(Object dat, CLList counterwiseOwner, CLList clockwiseOwner) { _dat = dat; clockwiseOwner.setCounterwiseHead(this); counterwiseOwner.setClockwiseHead(this); } /** * @param owner not used * @return */ Object getDat(CLList owner) { return _dat; } /** * @param owner * @return the owner itself */ CLList setDat (Object dat, CLList owner) { _dat = dat; return owner; } /** * @param dat * @param owner */ CLList insertClockwise(Object dat, CLList owner) { new DatNode (dat, owner, new CLList (EmptyNode.Singleton, this)); return owner; } /** * @param dat * @param owner */ CLList insertCounterwise (Object dat, CLList owner) { new DatNode (dat, new CLList (this, EmptyNode.Singleton), owner); return owner; } /** * Must distinguish the case when the owner has only one data element and * the case when the owner has more than one data element. * @param owner * @return */ Object remClockwise (CLList owner) { if (owner.equals (_clockwiseTail)) { owner.setClockwiseHead (EmptyNode.Singleton); owner.setCounterwiseHead (EmptyNode.Singleton); } else { owner.setClockwiseHead (_clockwiseTail.getClockwiseHead()); _clockwiseTail.setClockwiseHead (EmptyNode.Singleton); _clockwiseTail.setCounterwiseHead (EmptyNode.Singleton); } return _dat; /* // Perhaps less obvious is the following equivalent code: if (!owner.equals (_clockwiseTail)) { owner.setClockwiseHead (_clockwiseTail.getClockwiseHead()); } _clockwiseTail.setClockwiseHead (EmptyNode.Singleton); _clockwiseTail.setCounterwiseHead (EmptyNode.Singleton); return _dat; */ } /** * Must distinguish the case when the owner has only one data element and * the case when the owner has more than one data element. * @param owner * @return */ Object remCounterwise (CLList owner) { if (owner.equals (_counterwiseTail)) { owner.setClockwiseHead (EmptyNode.Singleton); owner.setCounterwiseHead (EmptyNode.Singleton); } else { owner.setCounterwiseHead (_counterwiseTail.getCounterwiseHead()); _counterwiseTail.setClockwiseHead (EmptyNode.Singleton); _counterwiseTail.setCounterwiseHead (EmptyNode.Singleton); } return _dat; /* // Perhaps less obvious is the following equivalent code: if (!owner.equals (_counterwiseTail)) { owner.setCounterwiseHead (_counterwiseTail.getCounterwiseHead()); } _clockwiseTail.setClockwiseHead (EmptyNode.Singleton); _clockwiseTail.setCounterwiseHead (EmptyNode.Singleton); return _dat; */ } /** * @param owner * @return */ CLList getClockwiseTail (CLList owner) { return _clockwiseTail; } /** * @param owner * @return */ CLList getCounterwiseTail (CLList owner) { return _counterwiseTail; } /** * @param algo * @param stop * @param input * @param owner * @return */ Object execute (ICLVisitor algo, CLList stop, Object input, CLList owner) { return algo.forNonEmpty(owner, stop, input); } /** * @param cllist */ void setClockwiseOwner(CLList cllist) { _clockwiseTail = cllist; } /** * @param cllist */ void setCounterwiseOwner(CLList cllist) { _counterwiseTail = cllist; } }