package rac; /** * A concrete data node of the internal doubly linked circular list of the RAC. * @author S. Wong */ public class RACDataNode extends ARACNode { private Object data; /** * Constructor for the RACDataNode. * @param data The data to be stored in this node. * @param next The node that is the next node in the list. * @param previous The node that is the previous node in the list. */ public RACDataNode(Object data, ARACNode next, ARACNode previous) { this.data = data; this.next = next; this.previous = previous; } /** * The visitor design pattern algorithm execution method. This method will * double dispatch to the dataCase() method of the supplied IRACVisitor. * @param param A generic parameter to be passed to the algorithm. * @param visitor The visitor algorithm to execute. * @return The return value of the algorithm. */ public Object execute(IRACVisitor visitor, Object param) { return visitor.dataCase(this, param); } /** * Accessor method to get the data object held in this node. * @return The data held in this node. */ public Object getData() { return data; } /** * Accessor method to set the data in this node. * @param data The data to be stored. */ public void setData(Object data) { this.data = data; } /** * Removes this node and returns the data object held. * @return The data object held in this node. */ public Object removeNode() { previous.setNext(next); next.setPrevious(previous); return data; } }