java.lang.Object
provided.listFW.NEList
- All Implemented Interfaces:
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-empty list.
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 accessing 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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalls the nonEmptyCase method of the IListAlgo parameter, passing to this method itself as the host parameter and the given input as the input parameter.getFirst()
Returns the first data element of this NEList.getRest()
Returns the first data element of this NEList.toString()
-
Field Details
-
_first
The first data element. -
_rest
The rest or "tail" of this NEList. Data Invariant: _rest != null;
-
-
Constructor Details
-
NEList
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.
-
-
Method Details
-
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.- Returns:
- The first data element of this list.
-
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.- Returns:
- The rest of this list.
-
execute
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. -
toString
-