|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.cmu.cs.crystal.util.ConsList<T>
T
- The type of elements this list holds.public abstract class ConsList<T>
An immutable cons list. Because this list cannot be modified, many
lists can share the same elements. Many operations must traverse,
and therefore run in linear time. Adding things to the front of the
list is done in constant time. Implements all methods of the List
interface, except those which are optional because they modify the
list in place.
Constructor Summary | |
---|---|
ConsList()
|
Method Summary | ||
---|---|---|
void |
add(int index,
T element)
|
|
boolean |
add(T e)
|
|
boolean |
addAll(Collection<? extends T> c)
|
|
boolean |
addAll(int index,
Collection<? extends T> c)
|
|
void |
clear()
|
|
static
|
concat(ConsList<T> front,
ConsList<T> back)
Concatenate the two given lists. |
|
static
|
cons(T hd,
ConsList<T> tl)
Create a new ConsList with hd as the
first element and tl as the rest of the list. |
|
boolean |
contains(Object o)
|
|
abstract boolean |
containsAll(Collection<?> c)
|
|
static
|
empty()
Create a new, empty list. |
|
ConsList<T> |
filter(Lambda<? super T,? extends Boolean> lam)
Given a 'first-class function' that takes elements of type T and returns a boolean, call that function on every element of this list, returning a new list that only contains
the elements for which the function call returned true. |
|
|
foldl(Lambda2<? super T,? super O,? extends O> lam,
O o)
Fold over the elements of this list. |
|
T |
get(int index)
|
|
abstract T |
hd()
Get the first element of this list. |
|
abstract int |
indexOf(Object o)
|
|
abstract boolean |
isEmpty()
|
|
Iterator<T> |
iterator()
|
|
abstract int |
lastIndexOf(Object o)
|
|
static
|
list(T... ts)
Create a ConsList with the given elements. |
|
ListIterator<T> |
listIterator()
Note: For ConsList<T> , this method is less efficient
than iterator() and should only be used if iterating
in the reverse direction is really important. |
|
ListIterator<T> |
listIterator(int index)
Note: For ConsList<T> , this method is less efficient
than iterator() and should only be used if iterating
in the reverse direction is really important. |
|
|
map(Lambda<? super T,? extends O> lam)
Given a 'first-class function' that takes elements of type T and returns elements of type O, call that function on every element of this list, returning a new list
of Os. |
|
T |
remove(int index)
|
|
boolean |
remove(Object o)
|
|
boolean |
removeAll(Collection<?> c)
|
|
ConsList<T> |
removeElement(T t)
Removes every element in the list where hd().equals(t) == true . |
|
ConsList<T> |
removeElementOnce(T t)
Removes the first element in the list where hd().equals(t) == true . |
|
boolean |
retainAll(Collection<?> c)
|
|
T |
set(int index,
T element)
|
|
static
|
singleton(T hd)
Create a list with one element. |
|
abstract int |
size()
|
|
ConsList<T> |
subList(int fromIndex,
int toIndex)
|
|
abstract ConsList<T> |
tl()
Return this list without the first element. |
|
Object[] |
toArray()
|
|
|
toArray(S[] a)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
equals, hashCode |
Constructor Detail |
---|
public ConsList()
Method Detail |
---|
public static <T> ConsList<T> empty()
public static <T> ConsList<T> singleton(T hd)
public static <T> ConsList<T> list(T... ts)
ConsList
with the given elements.
public static <T> ConsList<T> cons(T hd, ConsList<T> tl)
ConsList
with hd
as the
first element and tl
as the rest of the list.
public static <T> ConsList<T> concat(ConsList<T> front, ConsList<T> back)
public abstract T hd()
public abstract ConsList<T> tl()
public final ConsList<T> removeElement(T t)
hd().equals(t) == true
.
public final ConsList<T> removeElementOnce(T t)
hd().equals(t) == true
.
public final <O> ConsList<O> map(Lambda<? super T,? extends O> lam)
this
list, returning a new list
of Os.
public final ConsList<T> filter(Lambda<? super T,? extends Boolean> lam)
this
list, returning a new list that only contains
the elements for which the function call returned true.
public final <O> O foldl(Lambda2<? super T,? super O,? extends O> lam, O o)
public abstract int size()
size
in interface Collection<T>
size
in interface List<T>
public abstract boolean isEmpty()
isEmpty
in interface Collection<T>
isEmpty
in interface List<T>
public abstract int indexOf(Object o)
indexOf
in interface List<T>
public abstract int lastIndexOf(Object o)
lastIndexOf
in interface List<T>
public final ListIterator<T> listIterator(int index)
ConsList<T>
, this method is less efficient
than iterator()
and should only be used if iterating
in the reverse direction is really important. In particular,
calling the previous()
method is linear in the size
of the list.
listIterator
in interface List<T>
public final ListIterator<T> listIterator()
ConsList<T>
, this method is less efficient
than iterator()
and should only be used if iterating
in the reverse direction is really important. In particular,
calling the previous()
method is linear in the size
of the list.
listIterator
in interface List<T>
public final T get(int index)
get
in interface List<T>
public final Iterator<T> iterator()
iterator
in interface Iterable<T>
iterator
in interface Collection<T>
iterator
in interface List<T>
public abstract boolean containsAll(Collection<?> c)
containsAll
in interface Collection<T>
containsAll
in interface List<T>
public final ConsList<T> subList(int fromIndex, int toIndex)
subList
in interface List<T>
public final boolean contains(Object o)
contains
in interface Collection<T>
contains
in interface List<T>
public final Object[] toArray()
toArray
in interface Collection<T>
toArray
in interface List<T>
public final <S> S[] toArray(S[] a)
toArray
in interface Collection<T>
toArray
in interface List<T>
public final void add(int index, T element)
add
in interface List<T>
public final boolean add(T e)
add
in interface Collection<T>
add
in interface List<T>
public final boolean addAll(Collection<? extends T> c)
addAll
in interface Collection<T>
addAll
in interface List<T>
public final boolean addAll(int index, Collection<? extends T> c)
addAll
in interface List<T>
public final void clear()
clear
in interface Collection<T>
clear
in interface List<T>
public final T remove(int index)
remove
in interface List<T>
public final boolean remove(Object o)
remove
in interface Collection<T>
remove
in interface List<T>
public final boolean removeAll(Collection<?> c)
removeAll
in interface Collection<T>
removeAll
in interface List<T>
public final boolean retainAll(Collection<?> c)
retainAll
in interface Collection<T>
retainAll
in interface List<T>
public final T set(int index, T element)
set
in interface List<T>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |