package scheme; /** * Represents an abstract Scheme-like list, an immutable linear recursive * structure of data. Has abstract methods to provide its internal data and * structure to the client. Since an AList has an internal structure that is * isomorphic to itself, it's best to implement it using the composite pattern. * * @author Dung X. Nguyen * @version 1.0 * @since 09/10/00 * @Custom Copyright 2000 -All rights reserved */ public abstract class AList { /** * Returns the first element in this AList, if any. * The behavior for the empty list is undefined. */ public abstract Object getFirst(); /** * Returns the tail ("rest") of this AList, if any. * The behavior for the empty list is undefined. */ public abstract AList getRest(); /** * Returns the number of elements in this AList. */ public abstract int length(); /** * A tail recursive equivalent of the method length(). * Uses the "helper" method helpGetLength. */ public abstract int getLength(); /** * Computes the length of this AList given the accumulated * length of the part of the list that precedes it. * @param acc >=0, the accumulated length. */ protected abstract int helpGetLength(int acc); /** * A tail recursive way to compute the minimum od AList, * assuming it contains Integers. Uses the "helper" method helpGetMin. * @return int a minimum value for all Integer objects in this AList. */ public abstract int getMin(); /** * Helper for getMin(). * @param accMin the min of the list preceding this AList. */ protected abstract int helpGetMin(int accMin); }