package OOscheme; /** * Concrete implementation of the non-empty list interface, INEList. * Contains two pieces of data: * When a class contains other objects that are isomorphic to itself, * this class is called a composite.

* Provides concrete code for * Note the class is not public in order to hide from client code outside of * the OOscheme package. * @author Dung X. Nguyen * @since Copyright 2005 by DXN - All rights reserved */ public class NEList implements INEList { /** * The first data element of this NEList. */ private Object _first; /** * The rest or "tail" of this NEList. * Data Invariant: _rest != null; */ private IList _rest; /** * Initializes this NEList to a given first and rest. * @param first the first data element of this NEList. * @param tail != null, the rest of this NEList. */ public NEList(Object first, IList tail) { _first = first; _rest = tail; } /** * Returns the first data element of this NEList. * This method is marked as final to prevent all subclasses from * overriding it. Finalizing a method also allows the compiler to generate * more efficient calling code. */ final public Object getFirst() { return _first; } /** * Returns the rest of this NEList. * This method is marked as final to prevent all subclasses from * overriding it. Finalizing a method also allows the compiler to generate * more efficient calling code. */ final public IList getRest() { return _rest; } /** * Calls the nonEmptyCase method of the IListAlgo parameter, passing to this * method itself as the host parameter and the given input as the input * parameter. * This method is marked as final to prevent all subclasses from * overriding it. Finalizing a method also allows the compiler to generate * more efficient calling code. */ final public Object execute(IListAlgo algo, Object... inp) { return algo.nonEmptyCase(this, inp); } }