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.Collection
isEmpty
in interface java.util.List
public int size()
size
in interface java.util.Collection
size
in interface java.util.List
public 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.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.List
public 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.Object
public 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.Object
public 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.List
java.lang.UnsupportedOperationException
java.lang.ClassCastException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException
public boolean add(java.lang.Object elt) throws java.lang.UnsupportedOperationException, java.lang.ClassCastException, java.lang.IllegalArgumentException
add
in interface java.util.Collection
add
in interface java.util.List
java.lang.UnsupportedOperationException
java.lang.ClassCastException
java.lang.IllegalArgumentException
public 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.List
java.lang.UnsupportedOperationException
java.lang.ClassCastException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException
public boolean addAll(java.util.Collection c) throws java.lang.UnsupportedOperationException, java.lang.ClassCastException, java.lang.IllegalArgumentException
addAll
in interface java.util.Collection
addAll
in interface java.util.List
java.lang.UnsupportedOperationException
java.lang.ClassCastException
java.lang.IllegalArgumentException
public void clear() throws java.lang.UnsupportedOperationException
clear
in interface java.util.Collection
clear
in interface java.util.List
java.lang.UnsupportedOperationException
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
contains
in interface java.util.List
public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
containsAll
in interface java.util.List
public java.lang.Object get(int i) throws java.lang.IndexOutOfBoundsException
get
in interface java.util.List
java.lang.IndexOutOfBoundsException
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List
public java.lang.Object remove(int i) throws java.lang.UnsupportedOperationException
remove
in interface java.util.List
java.lang.UnsupportedOperationException
public boolean remove(java.lang.Object i) throws java.lang.UnsupportedOperationException
remove
in interface java.util.Collection
remove
in interface java.util.List
java.lang.UnsupportedOperationException
public boolean removeAll(java.util.Collection i) throws java.lang.UnsupportedOperationException
removeAll
in interface java.util.Collection
removeAll
in interface java.util.List
java.lang.UnsupportedOperationException
public boolean retainAll(java.util.Collection i) throws java.lang.UnsupportedOperationException
retainAll
in interface java.util.Collection
retainAll
in interface java.util.List
java.lang.UnsupportedOperationException
public java.lang.Object set(int i, java.lang.Object o) throws java.lang.UnsupportedOperationException
set
in interface java.util.List
java.lang.UnsupportedOperationException
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Collection
toArray
in interface java.util.List
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
toArray
in interface java.util.List
public java.util.List subList(int i, int j)
subList
in interface java.util.List
public java.util.ListIterator listIterator(int i)
listIterator
in interface java.util.List
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
public static void main(java.lang.String[] args)
Copyright 2003 Ralph Freese. All Rights Reserved.