package lrs; /** * Mutable linear recursive structure. * @author Dung X. Nguyen Copyright 2000 - All rights reserved. * @author Alan L. Cox * @since 02/13/01 * @dependency lrs.IAlgo */ public class LRStruct { private ANode _head; public LRStruct() { _head = EmptyNode.singleton; } /** * @return the String describing this list */ public final String toString() { return _head.toString(this); } /** * @return the object at the front of the list */ public final Object getFirst() { return _head.getFirst(this); } /** * @param data the object that replaces the one at the front of the list */ public final void setFirst(Object data) { _head.setFirst(data, this); } /** * @return the rest of the list */ public final LRStruct getRest() { return _head.getRest(this); } /** * @param tail the list that becomes the rest of the list */ public final void setRest(LRStruct tail) { _head.setRest(tail, this); } /** * @param data an object to insert at the front of the list */ public final void insertFront(Object data) { _head.insertFront(data, this); } /** * @return the object removed from the front of the list */ public final Object removeFront() { return _head.removeFront(this); } /** * The hook required by the visitor pattern. * * @param visitor The visitor object. * @param input An input that is passed to the visitor. * @return The result of the visitor. */ public final Object execute(IAlgo visitor, Object input) { return _head.execute(visitor, input, this); } // Package access only: /** * Initializes this LRStruct object with the given head node. * * @param head null != head. */ LRStruct(ANode head) { _head = head; } /** * This is the ``set state'' method required * by the state pattern. * * @param head The ANode that becomes the head of the list. */ final void setHead(ANode head) { _head = head; } /** * This is the ``get state'' method required * by the state pattern. * * @return The ANode at the head of the list. */ final ANode getHead() { return _head; } }