|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.latdraw.util.SimpleList
public class SimpleList
Simple Linked lists. Java's collection framework has LinkedList's but I need to guarentee that there is a great deal of sharing to save space (memory). For example, the space required to hold all subsets of an n element set requires space proportional to (n/2) 2n using vectors, but only 2n with linked lists.
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.
| Field Summary | |
|---|---|
static org.latdraw.util.SimpleList.EmptyList |
EMPTY_LIST
The empty list is a class constant |
protected java.lang.Object |
first
|
protected SimpleList |
rest
|
| Constructor Summary | |
|---|---|
SimpleList(java.util.Collection c)
|
|
SimpleList(java.lang.Object obj,
SimpleList list)
Constructs a list with obj followed by list. |
|
| Method Summary | |
|---|---|
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. |
SimpleList |
cons(java.lang.Object obj)
|
boolean |
contains(java.lang.Object o)
|
boolean |
containsAll(java.util.Collection c)
|
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)
|
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 obj)
|
boolean |
removeAll(java.util.Collection c)
|
SimpleList |
rest()
|
boolean |
retainAll(java.util.Collection c)
|
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()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
equals, hashCode |
| Field Detail |
|---|
protected java.lang.Object first
protected transient SimpleList rest
public static final org.latdraw.util.SimpleList.EmptyList EMPTY_LIST
| Constructor Detail |
|---|
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)
| Method Detail |
|---|
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 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.Listjava.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.Collectionadd in interface java.util.Listjava.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.Listjava.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.CollectionaddAll in interface java.util.Listjava.lang.UnsupportedOperationException
java.lang.ClassCastException
java.lang.IllegalArgumentException
public 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.List
public 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.List
public java.lang.Object remove(int i)
throws java.lang.UnsupportedOperationException
remove in interface java.util.Listjava.lang.UnsupportedOperationException
public boolean remove(java.lang.Object obj)
throws java.lang.UnsupportedOperationException
remove in interface java.util.Collectionremove in interface java.util.Listjava.lang.UnsupportedOperationException
public boolean removeAll(java.util.Collection c)
throws java.lang.UnsupportedOperationException
removeAll in interface java.util.CollectionremoveAll in interface java.util.Listjava.lang.UnsupportedOperationException
public boolean retainAll(java.util.Collection c)
throws java.lang.UnsupportedOperationException
retainAll in interface java.util.CollectionretainAll in interface java.util.Listjava.lang.UnsupportedOperationException
public 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.List
public 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)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||