ListEnumerator.java
Created with JBuilder
import java.util.Enumeration;
import OOscheme.*;

/**
 * Enumerates the objects contained within a list.  Also serves as a visitor
 * to check the host list for emptiness.
 * Serves an an example of visitor with states.
 * Illustrates the use of multiple inheritance.
 * @author Alan Cox
 */
public class ListEnumerator implements Enumeration, IListAlgo {
    private AList _list;

    /**
     * Initializes this Enumeration with the AList to be enumerated.
     * @param list the AList to be enumerated.
     */
    public ListEnumerator(AList list) {
	_list = list;
    }

    /**
     * Returns true if and only if their are more elements to
     * enumerate.  Otherwise, returns false.
     * @return boolean
     */
    public boolean hasMoreElements() {
	return ((Boolean)_list.execute(this, null)).booleanValue();
    }

    /**
     * Returns the next element.
     * @return Object
     */
    public Object nextElement() {
	Object first = _list.getFirst();
	_list = _list.getRest();
	return first;
    }

    /**
     * Returns Boolean.FALSE to indicate that the list has no more
     * elements to enumerate.
     * @param host an EmptyList
     * @param inp not used
     * @return Boolean
     */
    public Object emptyCase(AList host, Object inp) {
	return Boolean.FALSE;
    }

    /**
     * Returns Boolean.TRUE to indicate that the list has more
     * elements to enumerate.
     * @param host an NEList
     * @param inp not used
     * @return Boolean
     */
    public Object nonEmptyCase(AList host, Object inp) {
	return Boolean.TRUE;
    }
}


ListEnumerator.java
Created with JBuilder