public class List
extends java.util.AbstractList<java.lang.Object>
()
is actually a cons cell with the
empty flag switched on. Square pegs and round holes. This version of List
is built upon the AbstractList
and is both modifiable
and of variable size.AbstractSequentialList
December 11th 2005.)Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
car
The car of this List, and arbitrary Object.
|
protected List |
cdr
The cdr, or rest, of this list.
|
protected boolean |
empty
A flag to distinguish an empty list from an non-empty one.
|
static java.lang.String |
LPAREN |
static java.lang.String |
RPAREN |
Constructor and Description |
---|
List()
Creates a new empty list.
|
List(java.util.Collection<?> collection)
Creates a new list from the given Collection.
|
List(java.lang.Object[] array)
Creates a new list from the given object array.
|
List(java.lang.Object car,
List cdr)
Adds a new element onto an existing list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
java.lang.Object element)
As specified by the
AbstractList template. |
static List |
array2List(java.lang.Object obj) |
java.lang.Object |
caar()
The car of the car of this list.
|
java.lang.Object |
caddr()
The car of the cdr of the cdr.
|
java.lang.Object |
cadr()
The car of the cdr of this list.
|
java.lang.Object |
car()
The ubiquitous Lisp/Scheme car accessor.
|
java.lang.Object |
cdar()
The cdr of the car of this list.
|
List |
cddr()
The cdr of the cdr of this list.
|
List |
cdr()
The ubiquitous Lisp/Scheme cdr accessor.
|
java.lang.Object |
get(int index)
As specified by the
AbstractList template. |
boolean |
isEmpty()
Determines if this list is empty.
|
int |
length()
The length, or number of elements, in this list.
|
static List |
list()
A static convenience method, that creates new empty lists.
|
static List |
list(java.lang.Object o1)
A static convenience method, that creates a new singleton list.
|
static List |
list(java.lang.Object o1,
java.lang.Object o2)
A static convenience method, that creates a new list with two elements.
|
static List |
list(java.lang.Object a,
java.lang.Object b,
java.lang.Object c)
A static convenience method, that creates a new list with two elements.
|
static void |
main(java.lang.String[] args) |
java.lang.Object |
nth(int n)
Returns the nth element of this list, starting from zero.
|
java.lang.Object |
remove(int index)
As specified by the
AbstractList template. |
java.lang.Object |
set(int index,
java.lang.Object element)
As specified by the
AbstractList template. |
int |
size()
As specified by the
AbstractList template. |
protected List |
snoc(java.util.Iterator<?> iter)
Adds the contents of the Iterator object destructively onto the end of
this list.
|
protected List |
snoc(java.lang.Object obj)
Destructively updates this, which must be an empty list, so that
it's car in the obj passed in, and it's cdr is a new empty list.
|
protected List |
snoc(java.lang.Object[] array)
Adds the contents of the array of Objects destructively onto the end of
this list.
|
java.lang.String |
toString()
The unprettyprinted String representation of this list.
|
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public static final java.lang.String LPAREN
public static final java.lang.String RPAREN
protected java.lang.Object car
protected List cdr
protected boolean empty
public List()
public List(java.lang.Object car, List cdr)
car
- the new first element of the resulting new list.cdr
- the tail of the resulting new list.public List(java.util.Collection<?> collection)
collection
- the collection whose members will make up the new list.
It creates an new empty list if the collection is null.public List(java.lang.Object[] array)
array
- the object array whose members will make up the new list.
It creates an new empty list if the array reference is null.public static List array2List(java.lang.Object obj)
public int size()
AbstractList
template.
The length, or number of elements, in this list.size
in interface java.util.Collection<java.lang.Object>
size
in interface java.util.List<java.lang.Object>
size
in class java.util.AbstractCollection<java.lang.Object>
public java.lang.Object get(int index)
AbstractList
template.get
in interface java.util.List<java.lang.Object>
get
in class java.util.AbstractList<java.lang.Object>
public void add(int index, java.lang.Object element)
AbstractList
template.add
in interface java.util.List<java.lang.Object>
add
in class java.util.AbstractList<java.lang.Object>
public java.lang.Object remove(int index)
AbstractList
template.remove
in interface java.util.List<java.lang.Object>
remove
in class java.util.AbstractList<java.lang.Object>
public java.lang.Object set(int index, java.lang.Object element)
AbstractList
template.set
in interface java.util.List<java.lang.Object>
set
in class java.util.AbstractList<java.lang.Object>
public static List list()
public static List list(java.lang.Object o1)
o1
- the single element of the new list.public static List list(java.lang.Object o1, java.lang.Object o2)
o1
- the first element of the new list.o2
- the second element of the new list.public static List list(java.lang.Object a, java.lang.Object b, java.lang.Object c)
a
- the first element of the new list.b
- the second element of the new list.c
- the thrid element of the new list.public final java.lang.Object car()
-ea
flag
this will generate a failed assertion, otherwise null will be returned.public final List cdr()
-ea
flag
this will generate a failed assertion, otherwise null will be returned.public final java.lang.Object caar()
java.lang.ClassCastException
- if the car of the list is not a List, and
assertions are not enabled.public final java.lang.Object cadr()
public final java.lang.Object cdar()
java.lang.ClassCastException
- if the car of the list is not a List, and
assertions are not enabled.public final List cddr()
public final java.lang.Object caddr()
public java.lang.Object nth(int n)
n
- an int specifying the element to return, starting from zero.java.lang.NullPointerException
- if the list has fewer elements.public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Object>
isEmpty
in interface java.util.List<java.lang.Object>
isEmpty
in class java.util.AbstractCollection<java.lang.Object>
public int length()
public java.lang.String toString()
toString
in class java.util.AbstractCollection<java.lang.Object>
public static void main(java.lang.String[] args)
protected List snoc(java.lang.Object obj)
obj
- the new car.protected List snoc(java.util.Iterator<?> iter)
iter
- an Iterator.protected List snoc(java.lang.Object[] array)
array
- an array of objects.