OOscheme
Class NEList

java.lang.Object
  extended by OOscheme.NEList
All Implemented Interfaces:
IList, INEList

public class NEList
extends Object
implements INEList

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.

Since:
Copyright 2005 by DXN - All rights reserved
Author:
Dung X. Nguyen

Field Summary
private  Object _first
          The first data element of this NEList.
private  IList _rest
          The rest or "tail" of this NEList.
 
Constructor Summary
NEList(Object first, IList tail)
          Initializes this NEList to a given first and rest.
 
Method Summary
 Object execute(IListAlgo algo, Object... inp)
          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.
 Object getFirst()
          Returns the first data element of this NEList.
 IList getRest()
          Returns the rest of this NEList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_first

private Object _first
The first data element of this NEList.


_rest

private IList _rest
The rest or "tail" of this NEList. Data Invariant: _rest != null;

Constructor Detail

NEList

public NEList(Object first,
              IList tail)
Initializes this NEList to a given first and rest.

Parameters:
first - the first data element of this NEList.
tail - != null, the rest of this NEList.
Method Detail

getFirst

public final Object getFirst()
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.

Specified by:
getFirst in interface INEList
Returns:
this INElist's first element.

getRest

public final IList getRest()
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.

Specified by:
getRest in interface INEList
Returns:
this INElist's rest.

execute

public final Object execute(IListAlgo algo,
                            Object... inp)
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.

Specified by:
execute in interface IList
Parameters:
algo - the visitor, the algorithm to be executed.
inp - a variable number of input parameters to be used by the algorithm algo.
Returns:
an Object output from executing the algorithm algo; may be null.