lrs
Class LRStruct<T>

java.lang.Object
  extended by lrs.LRStruct<T>

public class LRStruct<T>
extends java.lang.Object

Mutable linear recursive structure.

 Visitor Pattern: Serves as a host capable of executing algorithms which are
 visitors.
 

Since:
8/25/05

Field Summary
private  ANode<T> _head
          The state of of this LRStruct.
 
Constructor Summary
LRStruct()
          Initializes this LRStruct to the empty state.
LRStruct(ANode<T> node)
          Initiazes this LRStruct with a given head node.
 
Method Summary
<R,P> R
execute(IAlgo<T,R,P> algo, P... inp)
          Hook method to execute an algorithm with a given input and return an appropriate output object.
 T getFirst()
          Gets the first data element from this LRStruct
(package private)  ANode<T> getHead()
          Gets the head node (i.e.
 LRStruct<T> getRest()
          Gets the rest of this LRStruct.
 LRStruct<T> insertFront(T dat)
          Inserts dat to the front of this LRStruct.
post condition: getFirst() now returns dat.
 T removeFront()
          Removes and returns this LRStruct's first.
 LRStruct<T> setFirst(T dat)
          Sets first data element to a new value.
(package private)  LRStruct<T> setHead(ANode<T> head)
          Changes the head node (i.e.
 LRStruct<T> setRest(LRStruct<T> tail)
          Sets a new tail for this LRStruct.
post condition: getRest() now returns tail.
 java.lang.String toString()
          Returns "()" if empty, otherwise returns the contents of this LRStruct enclosed in parentheses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_head

private ANode<T> _head
The state of of this LRStruct.

Constructor Detail

LRStruct

public LRStruct()
Initializes this LRStruct to the empty state.


LRStruct

LRStruct(ANode<T> node)
Initiazes this LRStruct with a given head node.

Parameters:
node - != null.
Method Detail

toString

public java.lang.String toString()
Returns "()" if empty, otherwise returns the contents of this LRStruct enclosed in parentheses.

Overrides:
toString in class java.lang.Object

insertFront

public final LRStruct<T> insertFront(T dat)
Inserts dat to the front of this LRStruct.
post condition: getFirst() now returns dat.

Parameters:
dat - data to be inserted.
Returns:
this LRStruct

removeFront

public final T removeFront()
Removes and returns this LRStruct's first.


getFirst

public final T getFirst()
Gets the first data element from this LRStruct


setFirst

public final LRStruct<T> setFirst(T dat)
Sets first data element to a new value.

Parameters:
dat - replaces the existing first for this LRStruct.
Returns:
this LRStruct
Throws:
NoSuchElementException - if this LRStruct is empty.

getRest

public final LRStruct<T> getRest()
Gets the rest of this LRStruct.

Throws:
NoSuchElementException - if this LRStruct is empty.

setRest

public final LRStruct<T> setRest(LRStruct<T> tail)
Sets a new tail for this LRStruct.
post condition: getRest() now returns tail.

Returns:
this LRStruct
Throws:
NoSuchElementException - if this LRStruct is empty.

execute

public final <R,P> R execute(IAlgo<T,R,P> algo,
                             P... inp)
Hook method to execute an algorithm with a given input and return an appropriate output object.

Parameters:
algo - an algorithm (!= null) that operates on this LRStruct.
inp - input variable argument list of objects needed by visitor algo.
Returns:
output object resulting from the execution of algo.

setHead

final LRStruct<T> setHead(ANode<T> head)
Changes the head node (i.e. state) of this LRStruct.

Parameters:
head - replaces the exisiting state of this LRStruct.
Returns:
this LRStruct

getHead

final ANode<T> getHead()
Gets the head node (i.e. state) of this LRStruct.

Returns:
the head node.