public class SimpleList
extends java.lang.Object
implements java.lang.Cloneable, java.util.List, java.io.Serializable
This version just has an element and a pointer to the rest, which is another LinkedList. This means push and pop not are supported but rest does not have to make a new object.
The rest of the empty list is itself.
 This class implements java.util.List.
 
Efficiency. size() takes time proportional to the size and get(int i) takes time proportional to i. Moral: do not use for loops to iterator over the elements; use the iterator. The former uses time proportional to n2 while the latter uses only n.
| Modifier and Type | Field and Description | 
|---|---|
static org.uacalc.util.SimpleList.EmptyList | 
EMPTY_LIST
The empty list is a class constant 
 | 
static org.uacalc.util.SimpleList.EmptyList | 
emptyList  | 
protected java.lang.Object | 
first  | 
protected SimpleList | 
rest  | 
| Constructor and Description | 
|---|
SimpleList(java.util.Collection c)  | 
SimpleList(java.lang.Object obj,
          SimpleList list)
Constructs a list with obj followed by list. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
add(int index,
   java.lang.Object elt)
This just throws an UnsupportedOperationException. 
 | 
boolean | 
add(java.lang.Object elt)
This just throws an UnsupportedOperationException. 
 | 
boolean | 
addAll(java.util.Collection c)  | 
boolean | 
addAll(int index,
      java.util.Collection c)
This just throws an UnsupportedOperationException. 
 | 
SimpleList | 
append(SimpleList lst)
This corresponds to  
(APPEND this lst) in lisp. | 
void | 
clear()
This just throws an UnsupportedOperationException. 
 | 
java.lang.Object | 
clone()  | 
SimpleList | 
cons(java.lang.Object obj)  | 
boolean | 
contains(java.lang.Object o)  | 
boolean | 
containsAll(java.util.Collection c)  | 
SimpleList | 
copyList()  | 
java.util.Enumeration | 
elements()  | 
java.lang.Object | 
first()  | 
java.util.Iterator | 
frontIterator(SimpleList tail)
This Iterator will iterate through the list until it reaches
 tail or to the end if tail is not found. 
 | 
java.lang.Object | 
get(int i)  | 
java.util.Iterator | 
getIterator()  | 
int | 
indexOf(java.lang.Object o)  | 
boolean | 
isEmpty()  | 
java.util.Iterator | 
iterator()  | 
int | 
lastIndexOf(java.lang.Object o)  | 
java.util.ListIterator | 
listIterator()  | 
java.util.ListIterator | 
listIterator(int i)  | 
static void | 
main(java.lang.String[] args)  | 
static SimpleList | 
makeList()  | 
static SimpleList | 
makeList(java.lang.Object obj)  | 
java.lang.Object | 
remove(int i)  | 
boolean | 
remove(java.lang.Object i)  | 
boolean | 
removeAll(java.util.Collection i)  | 
SimpleList | 
rest()  | 
boolean | 
retainAll(java.util.Collection i)  | 
SimpleList | 
reverse()  | 
SimpleList | 
reverse(SimpleList lst)
This is revappend in Common Lisp. 
 | 
java.lang.Object | 
set(int i,
   java.lang.Object o)  | 
int | 
size()
The size of the list. 
 | 
java.util.List | 
subList(int i,
       int j)  | 
java.lang.Object[] | 
toArray()  | 
java.lang.Object[] | 
toArray(java.lang.Object[] a)  | 
java.lang.String | 
toString()  | 
protected transient java.lang.Object first
protected transient SimpleList rest
public static org.uacalc.util.SimpleList.EmptyList EMPTY_LIST
public static org.uacalc.util.SimpleList.EmptyList emptyList
public SimpleList(java.lang.Object obj,
                  SimpleList list)
obj - The Object to be first.list - The List to be the rest.public SimpleList(java.util.Collection c)
public static SimpleList makeList()
public static SimpleList makeList(java.lang.Object obj)
public boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in interface java.util.Listpublic int size()
size in interface java.util.Collectionsize in interface java.util.Listpublic java.lang.Object first()
public SimpleList rest()
public SimpleList cons(java.lang.Object obj)
public java.util.Enumeration elements()
public java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listpublic java.util.Iterator frontIterator(SimpleList tail)
tail - a list == to a tail of the list.public java.util.Iterator getIterator()
public SimpleList copyList()
public java.lang.Object clone()
clone in class java.lang.Objectpublic SimpleList append(SimpleList lst)
(APPEND this lst) in lisp.public SimpleList reverse()
public SimpleList reverse(SimpleList lst)
 (APPEND (REVERSE this) lst) 
 public java.lang.String toString()
toString in class java.lang.Objectpublic void add(int index,
                java.lang.Object elt)
         throws java.lang.UnsupportedOperationException,
                java.lang.ClassCastException,
                java.lang.IllegalArgumentException,
                java.lang.IndexOutOfBoundsException
add in interface java.util.Listjava.lang.UnsupportedOperationExceptionjava.lang.ClassCastExceptionjava.lang.IllegalArgumentExceptionjava.lang.IndexOutOfBoundsExceptionpublic boolean add(java.lang.Object elt)
            throws java.lang.UnsupportedOperationException,
                   java.lang.ClassCastException,
                   java.lang.IllegalArgumentException
add in interface java.util.Collectionadd in interface java.util.Listjava.lang.UnsupportedOperationExceptionjava.lang.ClassCastExceptionjava.lang.IllegalArgumentExceptionpublic boolean addAll(int index,
                      java.util.Collection c)
               throws java.lang.UnsupportedOperationException,
                      java.lang.ClassCastException,
                      java.lang.IllegalArgumentException,
                      java.lang.IndexOutOfBoundsException
addAll in interface java.util.Listjava.lang.UnsupportedOperationExceptionjava.lang.ClassCastExceptionjava.lang.IllegalArgumentExceptionjava.lang.IndexOutOfBoundsExceptionpublic boolean addAll(java.util.Collection c)
               throws java.lang.UnsupportedOperationException,
                      java.lang.ClassCastException,
                      java.lang.IllegalArgumentException
addAll in interface java.util.CollectionaddAll in interface java.util.Listjava.lang.UnsupportedOperationExceptionjava.lang.ClassCastExceptionjava.lang.IllegalArgumentExceptionpublic void clear()
           throws java.lang.UnsupportedOperationException
clear in interface java.util.Collectionclear in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in interface java.util.Listpublic boolean containsAll(java.util.Collection c)
containsAll in interface java.util.CollectioncontainsAll in interface java.util.Listpublic java.lang.Object get(int i)
                     throws java.lang.IndexOutOfBoundsException
get in interface java.util.Listjava.lang.IndexOutOfBoundsExceptionpublic int indexOf(java.lang.Object o)
indexOf in interface java.util.Listpublic int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.Listpublic java.lang.Object remove(int i)
                        throws java.lang.UnsupportedOperationException
remove in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic boolean remove(java.lang.Object i)
               throws java.lang.UnsupportedOperationException
remove in interface java.util.Collectionremove in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic boolean removeAll(java.util.Collection i)
                  throws java.lang.UnsupportedOperationException
removeAll in interface java.util.CollectionremoveAll in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic boolean retainAll(java.util.Collection i)
                  throws java.lang.UnsupportedOperationException
retainAll in interface java.util.CollectionretainAll in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic java.lang.Object set(int i,
                            java.lang.Object o)
                     throws java.lang.UnsupportedOperationException
set in interface java.util.Listjava.lang.UnsupportedOperationExceptionpublic java.lang.Object[] toArray(java.lang.Object[] a)
toArray in interface java.util.CollectiontoArray in interface java.util.Listpublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.Listpublic java.util.List subList(int i,
                              int j)
subList in interface java.util.Listpublic java.util.ListIterator listIterator(int i)
listIterator in interface java.util.Listpublic java.util.ListIterator listIterator()
listIterator in interface java.util.Listpublic static void main(java.lang.String[] args)
Copyright 2003 Ralph Freese. All Rights Reserved.