lrs
Class LRStruct

java.lang.Object
  extended by lrs.LRStruct

public class LRStruct
extends java.lang.Object

Mutable linear recursive structure.

 

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

visitors.

Since:
10/09/01
Author:
Dung X. Nguyen Copyright 2001 - All rights reserved.

Field Summary
private  ANode _head
          The state of of this LRStruct.
 
Constructor Summary
LRStruct()
          Initializes this LRStruct to the empty state.
LRStruct(ANode node)
          Initiazes this LRStruct with a given head node.
 
Method Summary
 java.lang.Object execute(IAlgo algo, java.lang.Object inp)
          Hook method to execute an algorithm with a given input and return

an appropriate output object.

 java.lang.Object getFirst()
          Gets the first data element from this LRStruct
(package private)  ANode getHead()
          Gets the head node (i.e.
 LRStruct getRest()
          Gets the rest of this LRStruct.
 LRStruct insertFront(java.lang.Object dat)
          Inserts dat to the front of this LRStruct.

post condition: getFirst() now returns dat.

 java.lang.Object removeFront()
          Removes and returns this LRStruct's first.
 LRStruct setFirst(java.lang.Object dat)
          Sets first data element to a new value.
(package private)  LRStruct setHead(ANode head)
          Changes the head node (i.e.
 LRStruct setRest(LRStruct 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 _head
The state of of this LRStruct.

Constructor Detail

LRStruct

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


LRStruct

LRStruct(ANode 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 insertFront(java.lang.Object 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 java.lang.Object removeFront()
Removes and returns this LRStruct's first.


getFirst

public final java.lang.Object getFirst()
Gets the first data element from this LRStruct


setFirst

public final LRStruct setFirst(java.lang.Object 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 getRest()
Gets the rest of this LRStruct.

Throws:
NoSuchElementException - if this LRStruct is empty.

setRest

public final LRStruct setRest(LRStruct 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 java.lang.Object execute(IAlgo algo,
                                      java.lang.Object 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 object needed by visitor algo.
Returns:
output object resulting from the execution of algo.

setHead

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

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

getHead

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

Returns:
the head node.