package scheme; /** * Represents a non-empty list. * Implemented as a composite. * * @author Dung X. Nguyen * @version 1.0 * @since 09/10/00 * @Custom Copyright 2000 -All rights reserved */ public class NEList extends AList { private Object _first; private AList _rest; /** * Initializes this NEList to the given first and rest. * @param dat the first data element of this NEList. * @param tail the rest of this AList. */ public NEList(Object dat, AList tail) { _first = dat; _rest = tail; } /** * @return Object the first element of this NEList. */ public Object getFirst() { return _first; } /** * @return AList the rest of this NEList. */ public AList getRest() { return _rest; } /** * Returns the String representation of first data element followed by * the String representation of the rest. * @return String != null, != "". */ public String toString() { return _first.toString () + " " + _rest.toString(); } /** * Returns 1 + the number of elements of the rest. * @return int >= 1. */ public int length() { return 1 + _rest.length(); } /** * Asks the tail for help to compute the length, passing it an accumulated * length of 1, and returns the result. * @return int >= 1. */ public int getLength() { return _rest.helpGetLength (1); } /** * Adds 1 to the accumulated length, passes it down to the tail for help * to compute the length, and returns the result. * @return int > acc. */ protected int helpGetLength(int acc) { return _rest.helpGetLength (acc + 1); } /** * Asks _rest for help to compute the min, passing it the int value of * _first as the accumulated min. */ public int getMin() { return _rest.helpGetMin(((Integer)_first).intValue()); } /** * Computes the smaller of the accumulated min parameter and the value of * _first, and passes the result down to the tail for help to compute the min. */ protected int helpGetMin(int accMin) { return _rest.helpGetMin(Math.min(((Integer)_first).intValue(), accMin)); } }