Class lrs.LRStruct


public class LRStruct
extends Object
Mutable linear recursive structure.
Visitor Pattern: Serves as a host capable of executing algorithms which are
visitors.

Author:
Dung X. Nguyen Copyright 2001 - All rights reserved.

Variable Index

 o _head
The state of of this LRStruct

Constructor Index

 o LRStruct ()
Initializes this LRStruct to the empty state
 o LRStruct (ANode)
Initiazes this LRStruct with a given head node

Method Index

 o execute (IAlgo, Object)
Hook method to execute an algorithm with a given input and return
 o getFirst ()
Gets the first data element from this LRStruct
 o getHead ()
Gets the head node (i
 o getRest ()
Gets the rest of this LRStruct
 o insertFront (Object)
Inserts dat to the front of this LRStruct
 o removeFront ()
Removes and returns this LRStruct's first
 o setFirst (Object)
Sets first data element to a new value
 o setHead (ANode)
Changes the head node (i
 o setRest (LRStruct)
Sets a new tail for this LRStruct
 o toString ()
Returns "()" if empty, otherwise returns the contents of this

Variables

 o _head
private ANode _head
The state of of this LRStruct.

Constructors

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

 o LRStruct
 LRStruct(ANode node)
Initiazes this LRStruct with a given head node.

Parameters:
node - != null.

Methods

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

 o insertFront
public final LRStruct insertFront(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
 o removeFront
public final Object removeFront()
Removes and returns this LRStruct's first.

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

 o setFirst
public final LRStruct setFirst(Object dat)
Sets first data element to a new value.

Parameters:
dat - replaces the existing first for this LRStruct.
Returns:
this LRStruct
 o getRest
public final LRStruct getRest()
Gets the rest of this LRStruct.

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

Returns:
this LRStruct
 o execute
public final Object execute(IAlgo algo, 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.
 o setHead
final LRStruct setHead(ANode head)
Changes the head node (i.e. state) of this LRStruct.

Parameters:
head - replaces the exisiting state of this LRStruct.
Returns:
this LRStruct
 o getHead
final ANode getHead()
Gets the head node (i.e. state) of this LRStruct.

Returns:
the head node.