Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

OpenList Class Reference

List of all members.

Public Methods

Object first () throws OpenListException
OpenList rest () throws OpenListException
boolean isEmpty ()
boolean nonEmpty ()
int length ()
Object nth (int n) throws OpenListException
OpenList prefix (int n)
String toString ()
String toString (String leftParen, String spacer, String rightParen)

Static Public Methods

OpenList cons (Object _First, OpenList _Rest)
Object first (OpenList List) throws OpenListException
OpenList rest (OpenList List) throws OpenListException
boolean isEmpty (OpenList List)
boolean nonEmpty (OpenList List)
OpenList append (OpenList L1, OpenList L2)
OpenList reverse (OpenList L1)
void main (String arg[])

Static Public Attributes

String defaultLeftParen = "["
String defaultRightParen = "]"
String defaultSpacer = ", "
final OpenList nil = cons(null, null)
String firstOfOpenListException = "first() of empty list"
String restOfOpenListException = "rest() of empty list"

Detailed Description

OpenList is a type of uni-directional linked list that permits sharing of list tails. It is similar to the list representation used in many functional languages, such as rex, Lisp, etc.

Definition at line 13 of file OpenList.java.


Member Function Documentation

OpenList OpenList::append ( OpenList L1,
OpenList L2 ) [inline, static]
 

Create a new list formed by elements of the first argument followed by those of the second.

Parameters:
L1   the list providing the initial elements of the result
L2   the list providing the final elements of the result
Returns:
the list containing the elements of the first list followed by those of the second

Definition at line 222 of file OpenList.java.

Referenced by main().

OpenList OpenList::cons ( Object _First,
OpenList _Rest ) [inline, static]
 

Return a new OpenList constructed from its first and rest.

Parameters:
_First   the first Object in the list
_Rest   list of the rest of the objects in the list
Returns:
new OpenList from first and rest

Definition at line 89 of file OpenList.java.

Referenced by append(), main(), prefix(), and reverse().

Object OpenList::first ( OpenList List ) [inline, static]
 

Return the first of the argument, a non-empty OpenList.

Parameters:
List   the list the rest of which is to be returned
Returns:
first of the argument list
Exceptions:
OpenListException   if the argument happens to be empty

Definition at line 120 of file OpenList.java.

Object OpenList::first ( ) [inline]
 

Return the first of this non-empty OpenList.

Returns:
first of this list
Exceptions:
OpenListException   if this list happens to be empty

Definition at line 102 of file OpenList.java.

Referenced by append(), nth(), prefix(), reverse(), and toString().

boolean OpenList::isEmpty ( OpenList List ) [inline, static]
 

Return true if the argument list is empty, false otherwise. Note: Done by comparing this list to nil, which should be the only way to determine whether the list is empty.

Parameters:
List   the OpenList for which emptiness is to be determined
Returns:
true if the argument list is empty, false otherwise

Definition at line 193 of file OpenList.java.

boolean OpenList::isEmpty ( ) [inline]
 

Return true if this list is empty, false otherwise. Note: Done by comparing this list to nil, which should be the only way to determine whether the list is empty.

Returns:
true if this list is empty, false otherwise

Definition at line 167 of file OpenList.java.

Referenced by append(), first(), isEmpty(), prefix(), and rest().

int OpenList::length ( ) [inline]
 

Return the number of elements of this list.

Returns:
the number of elements of this list

Definition at line 262 of file OpenList.java.

Referenced by main(), and nth().

void OpenList::main ( String arg[] ) [inline, static]
 

test program: exercises a variety of the defined methods, printing out results

Definition at line 383 of file OpenList.java.

boolean OpenList::nonEmpty ( OpenList List ) [inline, static]
 

Return true if the argument list is non-empty, false otherwise.

Parameters:
List   the OpenList for which non-emptiness is to be determined
Returns:
true if the argument list is non-empty, false otherwise

Definition at line 206 of file OpenList.java.

boolean OpenList::nonEmpty ( ) [inline]
 

Return true if this list is non-empty, false otherwise.

Returns:
true if this list is non-empty, false otherwise

Definition at line 178 of file OpenList.java.

Referenced by length(), nonEmpty(), reverse(), and toString().

Object OpenList::nth ( int n ) [inline]
 

Return the nth element of this list, starting with n = 0, 1, 2, ... If there is no nth element, throws an EmptyList exception so indicating.

Parameters:
n   the index (0, 1, 2, ...) of the desired element.
Returns:
the nth element of this list.
Exceptions:
OpenListException   if there is no nth element

Definition at line 285 of file OpenList.java.

Referenced by main().

OpenList OpenList::prefix ( int n ) [inline]
 

Returns the first n elements of an OpenList. If there aren't n elements in the list, returns the entire list. If n <= 0, returns nil.

Parameters:
n   the length of the desired prefix of this list. return the prefix of this list of the desired length, or the entire list itself if the list is not as long as desired.

Definition at line 318 of file OpenList.java.

Referenced by main().

OpenList OpenList::rest ( OpenList List ) [inline, static]
 

Return the rest, i.e. all a list of all but the first of the argument non-empty OpenList.

ameter List the list the rest of which is to be returned
Returns:
rest of the argument list
Exceptions:
OpenListException   if the argument happens to be empty

Definition at line 154 of file OpenList.java.

OpenList OpenList::rest ( ) [inline]
 

Return the rest, i.e. all a list of all but the first of this non-empty OpenList.

Returns:
rest of this list
Exceptions:
OpenListException   if this list happens to be empty will be thrown.

Definition at line 135 of file OpenList.java.

Referenced by append(), length(), nth(), prefix(), reverse(), and toString().

OpenList OpenList::reverse ( OpenList L1 ) [inline, static]
 

Return a new list containing the elements of the argument list in reverse order.

Parameters:
L1   the list providing the elements
Returns:
the reverse of the argument list.

Definition at line 243 of file OpenList.java.

Referenced by main().

String OpenList::toString ( String leftParen,
String spacer,
String rightParen ) [inline]
 

Convert this OpenList to a String, using the arguments as punctuation.

Parameters:
leftParen   String that is output before the list elements
spacer   String that is output between list elements
rightParen   String that is output after the list elements
Returns:
String representing OpenList

Definition at line 352 of file OpenList.java.

String OpenList::toString ( ) [inline]
 

Convert this OpenList to a String, using default punctuation.

Returns:
String representing OpenList

Definition at line 335 of file OpenList.java.


Member Data Documentation

String OpenList::defaultLeftParen = "[" [static]
 

the default left paren used when a list is printed. Defaults are used when the toString() method is called, i.e. whenever an OpenList is automatically cast to a String, as in printing. To use different punctuation, or no punctuation, use the three-argument toString, and supply the punctuation you want.

Definition at line 23 of file OpenList.java.

String OpenList::defaultRightParen = "]" [static]
 

the default right paren used when a list is printed

Definition at line 28 of file OpenList.java.

String OpenList::defaultSpacer = ", " [static]
 

the default space used when a list is printed

Definition at line 33 of file OpenList.java.

String OpenList::firstOfOpenListException = "first() of empty list" [static]
 

exception message for first of empty list

Definition at line 48 of file OpenList.java.

final OpenList OpenList::nil = cons(null, null) [static]
 

the one and only empty OpenList. Do not create any others. This list is represented by a unique cell allocated for the purpose. The first and rest are not intended to be used. We do not use null for this list, so that we can call methods on it.

Definition at line 43 of file OpenList.java.

String OpenList::restOfOpenListException = "rest() of empty list" [static]
 

exception message for rest of empty list

Definition at line 53 of file OpenList.java.


The documentation for this class was generated from the following file:
Generated at Mon Sep 30 00:51:55 2002 for OpenList by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001