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

OpenList Class Reference

Inheritance diagram for OpenList::

Cloneable List of all members.

Public Methods

OpenList cons (Object _First)
Object first () throws OpenListException
OpenList rest () throws OpenListException
boolean isEmpty ()
boolean nonEmpty ()
OpenList append (OpenList L2)
boolean member (Object Ob)
OpenList reverse ()
int length ()
Object nth (int n) throws OpenListException
OpenList prefix (int n)
Object second () throws OpenListException
Object third () throws OpenListException
boolean equals (Object Ob)
Object clone ()
OpenList map (Function1 f)
Object reduce (Function2 b, Object u)
String toString ()
String toString (String leftParen, String spacer, String rightParen)
String implode ()
Object [] toArray ()
OpenList sort (java.util.Comparator comparator)
Enumeration elements ()

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)
boolean member (Object Ob, OpenList L)
OpenList reverse (OpenList L1)
int length (OpenList L)
Object nth (int n, OpenList L) throws OpenListException
OpenList prefix (int n, OpenList L)
Object second (OpenList L) throws OpenListException
Object third (OpenList L) throws OpenListException
OpenList list ()
OpenList list (Object First)
OpenList list (Object First, Object Second)
OpenList list (Object First, Object Second, Object Third)
OpenList list (Object First, Object Second, Object Third, Object Fourth)
OpenList list (Object First, Object Second, Object Third, Object Fourth, Object Fifth)
OpenList list (Object First, Object Second, Object Third, Object Fourth, Object Fifth, Object Sixth)
OpenList list (Object First, Object Second, Object Third, Object Fourth, Object Fifth, Object Sixth, Object Seventh)
boolean equals (OpenList L1, OpenList L2)
OpenList map (Function1 f, OpenList L)
OpenList mappend (Function1 f, OpenList L)
Object reduce (Function2 b, Object u, OpenList L)
OpenList assoc (Object X, OpenList L)
OpenList explode (String s)
String implode (OpenList L)
Object [] toArray (OpenList L)
OpenList fromArray (Object a[])
OpenList readLines (BufferedReader reader) throws IOException
OpenList solidify (Enumeration E)
void main (String arg[])

Static Public Attributes

final OpenList nil = cons(null, null)
String defaultLeftParen = "["
String defaultRightParen = "]"
String defaultSpacer = ", "
String firstException = "first() of empty list"
String restException = "rest() of empty list"
String nthException = "nth of an OpenList of length "
String wherePart = ", where n == "
String secondException
String thirdException = "third of an OpenList, where length() = "

Detailed Description

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

Definition at line 14 of file OpenList.java.


Member Function Documentation

OpenList OpenList::append ( OpenList L2 ) [inline]
 

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

Parameters:
L   the list providing the final elements of the result
Returns:
the list containing the elements of this list followed by those of the second

Definition at line 280 of file OpenList.java.

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 258 of file OpenList.java.

OpenList OpenList::assoc ( Object X,
OpenList L ) [inline, static]
 

Find out whether the first argument occurs as the first element of any pair in the second argument, an association list. If it does, return the entire pair. If not, return the empty list.

 assoc(S, []) => [];
 
 assoc(S, [[S, T] | L]) => [S, T];

 assoc(S, [_ | L]) => assoc(S, L);
 *

Definition at line 859 of file OpenList.java.

Object OpenList::clone ( ) [inline]
 

Return a clone of this OpenList. Any Cloneable Objects in the list will be cloned in the result. Non-Cloneable Objects will be included as is.

Returns:
Object which is really an OpenList (for conformance to the Cloneable interface)

Definition at line 741 of file OpenList.java.

OpenList OpenList::cons ( Object _First ) [inline]
 

Return a new OpenList constructed from this list and a first.

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

Definition at line 126 of file OpenList.java.

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 113 of file OpenList.java.

Enumeration OpenList::elements ( ) [inline]
 

Return an Enumeration of the elements of this OpenList.

Returns:
an Enumeration of the elements of this OpenList

Definition at line 1083 of file OpenList.java.

boolean OpenList::equals ( Object Ob ) [inline]
 

Return true if this list is equal to the argument list.

Parameters:
Ob   the Object to be compared with this for equality
Returns:
true if the argument is an OpenList equal to this one.

Definition at line 723 of file OpenList.java.

boolean OpenList::equals ( OpenList L1,
OpenList L2 ) [inline, static]
 

Return true if the two OpenLists are equal, in the sense of having the equal elements in both listss.

Parameters:
L1   one of two OpenLists to be compared for equality
L2   the other of two OpenLists to be compared for equality
Returns:
true if the arguments are equal, false otherwise

Definition at line 693 of file OpenList.java.

Referenced by main().

OpenList OpenList::explode ( String s ) [inline, static]
 

Explode the argument String into a list of Characters wrapping the characters of the String.

Parameters:
String   to be exploded
Returns:
OpenList containing the characters of the String

Definition at line 930 of file OpenList.java.

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 157 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 139 of file OpenList.java.

Referenced by append(), assoc(), equals(), implode(), map(), mappend(), member(), OpenListEnumeration::nextElement(), nth(), reduce(), reverse(), toArray(), and toString().

OpenList OpenList::fromArray ( Object a[] ) [inline, static]
 

Create an OpenList from an array of Objects.

Returns:
an OpenList containing the Objects in the argument array

Definition at line 1024 of file OpenList.java.

String OpenList::implode ( ) [inline]
 

Implode this OpenList into a single String. The list can contain any Objects, not just Characters. The toString method is used to get the character representation of the object. No parentheses or spacing is added around or between the elements of the outer list.

Returns:
String representing the imploded list.

Definition at line 978 of file OpenList.java.

String OpenList::implode ( OpenList L ) [inline, static]
 

Implode the contents of an OpenList into a single String. The list can contain any Objects, not just Characters. The toString method is used to get the character representation of the object. No parentheses or spacing is added around or between the elements of the outer list. If these are wanted, use the toString method rather than implode.

Parameters:
L   the list to be imploded
Returns:
String representing the imploded list.

Definition at line 955 of file OpenList.java.

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 229 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 203 of file OpenList.java.

Referenced by append(), equals(), isEmpty(), map(), mappend(), and OpenListEnumeration::nextElement().

int OpenList::length ( ) [inline]
 

Return the number of elements of this list.

Returns:
the number of elements of this list

Definition at line 381 of file OpenList.java.

Referenced by main(), nth(), and toArray().

int OpenList::length ( OpenList L ) [inline, static]
 

Return the number of elements of the argument list.

Parameters:
L   the list, the length of which is to be determined
Returns:
the number of elements of the argument list

Definition at line 362 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second,
Object Third,
Object Fourth,
Object Fifth,
Object Sixth,
Object Seventh ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Third   the third element in the resulting list
Fourth   the fourth element in the resulting list
Fifth   the fifth element in the resulting list
Sixth   the sixth element in the resulting list
Seventh   the seventh element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 672 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second,
Object Third,
Object Fourth,
Object Fifth,
Object Sixth ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Third   the third element in the resulting list
Fourth   the fourth element in the resulting list
Fifth   the fifth element in the resulting list
Sixth   the sixth element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 648 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second,
Object Third,
Object Fourth,
Object Fifth ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Third   the third element in the resulting list
Fourth   the fourth element in the resulting list
Fifth   the fifth element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 626 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second,
Object Third,
Object Fourth ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Third   the third element in the resulting list
Fourth   the fourth element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 606 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second,
Object Third ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Third   the third element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 590 of file OpenList.java.

OpenList OpenList::list ( Object First,
Object Second ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Second   the second element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 574 of file OpenList.java.

OpenList OpenList::list ( Object First ) [inline, static]
 

Return the list consisting of the argument objects.

Parameters:
First   the first element in the resulting list
Returns:
the list consisting of the argument objects

Definition at line 560 of file OpenList.java.

OpenList OpenList::list ( ) [inline, static]
 

Return the list consisting of the argument objects, in this case the empty list.

Returns:
the list consisting of the argument objects

Definition at line 547 of file OpenList.java.

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

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

Definition at line 1113 of file OpenList.java.

OpenList OpenList::map ( Function1 f ) [inline]
 

Map a Function1 f over this OpenList.

Parameters:
f   a member of a class that implements the Function1 interface, i.e. that provides a method Object apply(Object).
Returns:
A list resulting from applying f to each element of L

Definition at line 779 of file OpenList.java.

OpenList OpenList::map ( Function1 f,
OpenList L ) [inline, static]
 

Map a Function1 function object f over an OpenList L.

Parameters:
f   a member of a class that implements the Function1 interface, i.e. that provides a method Object apply(Object).
L   a list, the elements of which will be arguments of f
Returns:
A list resulting from applying f to each element of L

Definition at line 759 of file OpenList.java.

OpenList OpenList::mappend ( Function1 f,
OpenList L ) [inline, static]
 

Map a Function1 function object f over an OpenList L, where the function is expected to produce a list for each object, then append the results together to get an overall list.

Parameters:
f   a member of a class that implements the Function1 interface, i.e. that provides a method Object apply(Object).
L   a list, the elements of which will be arguments of f
Returns:
A list resulting from applying f to each element of L then appending the results together.

Definition at line 796 of file OpenList.java.

boolean OpenList::member ( Object Ob ) [inline]
 

Return true if the first argument is a member (in the sense of being equals) of this OpenList

Parameters:
Ob   the object being tested for membership
Returns:
true if the first argument is a member of this list, false otherwise

Definition at line 316 of file OpenList.java.

boolean OpenList::member ( Object Ob,
OpenList L ) [inline, static]
 

Return true if the first argument is a member (in the sense of being equals) of the second argument list

Parameters:
Ob   the object being tested for membership
L   the list in which membership is to be tested
Returns:
true if the first argument is a member of the second, false otherwise

Definition at line 296 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 242 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 214 of file OpenList.java.

Referenced by assoc(), equals(), OpenListEnumeration::hasMoreElements(), implode(), length(), member(), nonEmpty(), reduce(), reverse(), toArray(), 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 430 of file OpenList.java.

Object OpenList::nth ( int n,
OpenList L ) [inline, static]
 

Return the nth element of the second argument list, starting with n = 0, 1, 2, ... If there is no nth element, throws an OpenListException so indicating.

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

Definition at line 399 of file OpenList.java.

Referenced by main().

OpenList OpenList::prefix ( int n,
OpenList L ) [inline, static]
 

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.
L   the list, the prefix of which is to be extracted
Returns:
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 466 of file OpenList.java.

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

Returns the first n elements of this 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.
Returns:
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 445 of file OpenList.java.

Referenced by main(), and prefix().

OpenList OpenList::readLines ( BufferedReader reader ) [inline, static]
 

Read lines from a BufferedReader, each as a separate String. The lines read are returned as an OpenList of Strings.

Parameters:
reader   reads the lines that are compiled into a list
Returns:
list of Strings read, one String per line

Definition at line 1067 of file OpenList.java.

Object OpenList::reduce ( Function2 b,
Object u ) [inline]
 

Reduce this OpenList using Function2 b and unit u.

Parameters:
b   a member of a class that implements the Function2 interface, i.e. that provides a method Object apply(Object, Object).
u   the unit for the function b. This will be the value returned
L   the list to be reduced by the function b.
Returns:
A list resulting from applying f to each element of this.

Definition at line 839 of file OpenList.java.

Object OpenList::reduce ( Function2 b,
Object u,
OpenList L ) [inline, static]
 

Reduce an OpenList using Function2 b and unit u.

Parameters:
b   a member of a class that implements the Function2 interface, i.e. that provides a method Object apply(Object, Object).
u   the unit for the function b. This will be the value returned if L is the empty list.
L   the list to be reduced by the function b.
Returns:
A list resulting from applying f to each element of L

Definition at line 819 of file OpenList.java.

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 190 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

Definition at line 171 of file OpenList.java.

Referenced by append(), assoc(), equals(), implode(), length(), map(), mappend(), member(), OpenListEnumeration::nextElement(), nth(), reduce(), reverse(), toArray(), and toString().

OpenList OpenList::reverse ( ) [inline]
 

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

Returns:
the reverse of this list

Definition at line 350 of file OpenList.java.

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 330 of file OpenList.java.

Object OpenList::second ( OpenList L ) [inline, static]
 

Return the second element of the argument OpenList, assuming it has one.

Parameters:
L   an OpenList, the second element of which is to be extracted
Returns:
the second element L
Exceptions:
OpenListException   if there is no second element

Definition at line 520 of file OpenList.java.

Object OpenList::second ( ) [inline]
 

Return the second element of this OpenList, assuming it has one.

Returns:
the second element of this OpenList
Exceptions:
OpenListException   if there is no second element

Definition at line 479 of file OpenList.java.

Referenced by second().

OpenList OpenList::solidify ( Enumeration E ) [inline, static]
 

Create an OpenList of the elements from an Enumeration.

Parameters:
E   an Enumeration that provides the elements for a new OpenList
Returns:
an OpenList of the elements from an Enumeration

Definition at line 1095 of file OpenList.java.

OpenList OpenList::sort ( java.util.Comparator comparator ) [inline]
 

Return a sorted version of this list, as determined by the Comparator, using the Quicksort algorithm

Parameters:
comparator   used to determine whether one element is less than another
Returns:
the list consisting of the Objects in the original list in order as determined by the comparator

Definition at line 1047 of file OpenList.java.

Object OpenList::third ( OpenList L ) [inline, static]
 

Return the third element of the argument OpenList, assuming it has one.

Parameters:
L   an OpenList, the third element of which is to be extracted
Returns:
the second element L
Exceptions:
OpenListException   if there is no third element

Definition at line 534 of file OpenList.java.

Object OpenList::third ( ) [inline]
 

Return the third element of this OpenList, assuming it has one.

Returns:
the third element of this OpenList
Exceptions:
OpenListException   if there is no third element

Definition at line 499 of file OpenList.java.

Referenced by third().

Object[] OpenList::toArray ( ) [inline]
 

Return an array of the Objects in this OpenList.

Returns:
an array of the Objects in this OpenList

Definition at line 1012 of file OpenList.java.

Object [] OpenList::toArray ( OpenList L ) [inline, static]
 

Return an array of the Objects in the argument OpenList.

Parameters:
L   the list of objects to be used as elements of the array
Returns:
an array of the Objects in the argument OpenList

Definition at line 991 of file OpenList.java.

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 896 of file OpenList.java.

String OpenList::toString ( ) [inline]
 

Convert this OpenList to a String, using default punctuation.

Returns:
String representing this OpenList

Definition at line 881 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 36 of file OpenList.java.

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

the default right paren used when a list is printed

Definition at line 41 of file OpenList.java.

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

the default space used when a list is printed

Definition at line 46 of file OpenList.java.

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

exception message for first of empty list

Definition at line 51 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. We do not create other empty lists so that our implementation of isEmpty() works by comparing references.

Definition at line 25 of file OpenList.java.

String OpenList::nthException = "nth of an OpenList of length " [static]
 

exception message for nth of a list

Definition at line 61 of file OpenList.java.

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

exception message for rest of empty list

Definition at line 56 of file OpenList.java.

String OpenList::secondException [static]
 

Initial value:

 
                                     "second of an OpenList, where length() = "
exception message for second of a list

Definition at line 71 of file OpenList.java.

String OpenList::thirdException = "third of an OpenList, where length() = " [static]
 

exception message for third of a list

Definition at line 77 of file OpenList.java.

String OpenList::wherePart = ", where n == " [static]
 

part of exception message for nth of a list

Definition at line 66 of file OpenList.java.


The documentation for this class was generated from the following file:
Generated at Wed Feb 19 23:28:37 2003 for OpenList by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001