scranton.list
Class RecursiveListViaLinear1Ind

java.lang.Object
  extended byscranton.Linear1
      extended byscranton.Linear1Ind
          extended byscranton.list.RecursiveListViaLinear1Ind
All Implemented Interfaces:
RecursiveList

public class RecursiveListViaLinear1Ind
extends Linear1Ind
implements RecursiveList

A implementation of the RecursiveList paradigm using the Linear1Ind class, the implementation represents an empty list with a "null object".

Specifications:
A RecursiveList is
  • empty, L=() - maps to this.getLink() == null
  • or L = (h, T), where h is an object called the head - maps to (h, T) = (this.getLink().getData(), this.getLink().getLink()) and T is a, possibly empty, RecursiveList, called the tail

Initial Value:
L = () - maps to this.getLink()==null


Field Summary
 
Fields inherited from class scranton.Linear1
data, link
 
Constructor Summary
RecursiveListViaLinear1Ind()
          Constructs a "null object", (null, ()).
RecursiveListViaLinear1Ind(java.lang.Object o)
          Constructs a Linear1 object containing o as its head and an empty tail, (o, ()).
 
Method Summary
 Linear1 factory()
          Returns a null Linear1() object
 java.lang.Object headOf()
          Returns reference to the Object at the head of the list.
 void insert(RecursiveList B)
          Replaces the current list with a new list composed by concatenating the current list to the list in the parameter, this = L+this.
 boolean isEmpty()
          Returns true if the current list is empty.
 RecursiveList remove()
          If this = (h, T), remove the current list and replace it by its tail, this' = T, return (h, ()).
 RecursiveList tailOf()
          Returns reference to the tail of the current list.
 java.lang.String toString()
          Returns a string representation of the list.
 
Methods inherited from class scranton.Linear1Ind
indInsert, indRemove, indReplace, indView
 
Methods inherited from class scranton.Linear1
getData, getLink, setData, setLink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RecursiveListViaLinear1Ind

public RecursiveListViaLinear1Ind()
Constructs a "null object", (null, ()).


RecursiveListViaLinear1Ind

public RecursiveListViaLinear1Ind(java.lang.Object o)
Constructs a Linear1 object containing o as its head and an empty tail, (o, ()).

Parameters:
o - The object to be referenced by this Linear1Ind object.
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: RecursiveList
Returns true if the current list is empty.
Specifications:
Returns this==()?

Specified by:
isEmpty in interface RecursiveList
Returns:
this==()
See Also:
RecursiveList.isEmpty()

headOf

public java.lang.Object headOf()
Description copied from interface: RecursiveList
Returns reference to the Object at the head of the list.
Specifications:
this!=()
this' = this = (h,T)
Returns h

Timing:
O(constant)

Specified by:
headOf in interface RecursiveList
Returns:
Object Head of the list.

tailOf

public RecursiveList tailOf()
Description copied from interface: RecursiveList
Returns reference to the tail of the current list.
Specifications:
this!=()
this' = this = (h,T)

Timing:
O(constant)

Specified by:
tailOf in interface RecursiveList
Returns:
RecursiveList Returns reference to the tail of the current list.

insert

public void insert(RecursiveList B)
Description copied from interface: RecursiveList
Replaces the current list with a new list composed by concatenating the current list to the list in the parameter, this = L+this.
Specifications:
this'= L + this

Specified by:
insert in interface RecursiveList
Parameters:
B - List that will be prepended to this.
See Also:
RecursiveList.insert(scranton.list.RecursiveList)

remove

public RecursiveList remove()
Description copied from interface: RecursiveList
If this = (h, T), remove the current list and replace it by its tail, this' = T, return (h, ()).
Specifications:
this!=()
this=(h,T)
this'=T
Return (h, ())

Timing:
O(constant)

Specified by:
remove in interface RecursiveList
Returns:
RecursiveList Returns the tail of the current list.

toString

public java.lang.String toString()
Description copied from interface: RecursiveList
Returns a string representation of the list. Returns the string representation, "[head \t tail]" or "[]" is the list is empty.

Specified by:
toString in interface RecursiveList
Overrides:
toString in class Linear1Ind
Returns:
String Returns a tab delimited string of the objects in the recursive Linear1 structure.

factory

public Linear1 factory()
Description copied from class: Linear1
Returns a null Linear1() object

Overrides:
factory in class Linear1
Returns:
A null Linear1() object