Class listFW.NEList
- public class NEList
- extends Object
- implements listFW.IList
Represents non-empty lists.
Contains two pieces of data:
- first: an Object representing the first data element
- rest: an IList object representing the rest of this non-emptylist.
When a class contains other objects that are isomorphic to itself,
this class is called a composite.
Provides concrete code for
- a constructor to initialize this NEList to a given first and rest,
- the getFirst() method for accessing the first data element,
- the getRest() method for accesssing the rest of the list,
- the execute method: simply calls the nonEmptyCase method of the IListAlgo
parameter, passing to this method itself as the host and the given input
Object as the input.
- Author:
- D. X. Nguyen, S. B. Wong

_first
- The first data element
_rest
- The rest or "tail" of this NEList

NEList
(Object, IList)
- Initializes this NEList to a given first and a given rest

execute
(IListAlgo, Object)
- Calls the nonEmptyCase method of the IListAlgo parameter, passing to this
getFirst
()
- Returns the first data element of this NEList
getRest
()
- Returns the first data element of this NEList

_first
private Object _first
- The first data element.
_rest
private IList _rest
- The rest or "tail" of this NEList.
Data Invariant: _rest != null;

NEList
public NEList(Object f, IList r)
- Initializes this NEList to a given first and a given rest.
- Parameters:
- f - the first element of this NEList.
- r - != null, the rest of this NEList.

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