package lrs; /** * Mutable linear recursive structure. Serves as a host to algorithms that conform * to the visitor pattern. * @author Dung X. Nguyen Copyright 2000 - All rights reserved. * @since 02/15/00 * @dependency lrs.IAlgo */ public class LRStruct { /** @SBGen Variable (,state,,64) */ private ANode _head; /** * Initializes this LRStruct to an empty state. */ public LRStruct () { _head = NullNode.singleton; } /** * Inserts dat to the front of this LRStruct. * @param dat data to insert at this node */ public final void insertFront (Object dat) { _head.insertFront (dat, this); } /** * Returns this node's first */ public final Object removeFront () { return _head.removeFront (this); } /** * Gets the data from this node */ public final Object getFirst() { return _head.getFirst (this); } /** * Sets first data element to a new value. * @param dat new data for this node * @throws NoSuchElementException if this LRStruct is empty. */ public final void setFirst (Object dat) { _head.setFirst (dat, this); } /** * Gets the rest of the structure * @throws NoSuchElementException if this LRStruct is empty. */ public final LRStruct getRest () { return _head.getRest (this); } /** * Sets a new tail for this node * @throws NoSuchElementException if this LRStruct is empty. */ public final void setRest (LRStruct tail) { _head.setRest (tail, this); } /** * Serves as a host to execute an algorithm with a given input and return an appropriate * output object. * @param visitor an algorithm (!= null) that operates on LRStruct. * @param input input object needed by visitor. * @return output object resulting from the execution of visitor. */ public final Object execute (IAlgo visitor, Object input) { return _head.execute (visitor, input, this); } // Package access only: /** * Initiazes this LRStruct with a given head node. * @param node null != node. */ LRStruct(ANode node) { _head = node; } /** * Changes the head node (i.e. state) of this LRStruct. * @param head */ final void setHead (ANode head) { _head = head; } /** * Gets the head node (i.e. state) of this LRStruct. * @return the head node. */ final ANode getHead () { return _head; } }