NEList.java
Created with JBuilder

/**
 * Represents a non-empty list.
 * Implemented as a composite.
 * @author Dung X. Nguyen
 * @version 1.1
 * @since 01/25/02
 * @Custom Copyright 2002 -All rights reserved
 */
public class NEList extends AList {
    /**
     * The first element of this NEList.
     */
    private Object _first;

    /**
     * The "tail" (or "rest") of this NEList.
     */
    private AList _rest;

    /**
     * Initializes this NEList to the given first and rest.
     * @param dat the first data element of this NEList.
     * @param tail != null, the rest of this AList.
     */
    public NEList(Object dat, AList tail) {
        _first = dat;
        _rest = tail;
    }

    /**
    * Returns the first element of this NEList.
    * @return an Object (may be null).
    */
    public Object getFirst() {
        return _first;
    }

    /**
    * Returns the rest of this NEList.
    * @return AList != null.
    */
    public AList getRest() {
        return _rest;
    }

    /**
     * Returns a String representation of this NEList. 
* @return "(" followed by the String representation of first data element, * followed by a space, followed by the String representation of the rest, * followed by ")". */ public String toString() { return "(" + _first + " " + _rest + ")"; } /** * Returns 1 + the number of elements in the rest of this NEList. * @return int > 0. */ public int getLength() { return 1 + _rest.getLength(); } }
NEList.java
Created with JBuilder