|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.iter.AbstractIterable<T>
edu.rice.cs.plt.collect.ConsList<T>
public abstract class ConsList<T>
A Lisp- or Scheme-style immutable list. A ConsList is either an ConsList.Empty
or a ConsList.Nonempty; operations may be defined on the lists by implementing ConsVisitor.
While ComposedIterable provides similar facilities for creating
lists, ConsLists provide a more efficient means of decomposing lists --
because there is no rest operation on Iterables in general, the only way to
produce an Iterable sublist of an Iterable is to make a copy. With a
well-designed ConsList, on the other hand, producing a sublist is trivial.
This class also defines a few static convenience methods to simplify
client code. A static import (import static edu.rice.cs.plt.collect.ConsList.*)
will eliminate the need for explicit name qualifiers when using these methods.
| Nested Class Summary | |
|---|---|
static class |
ConsList.Empty<T>
The empty variant of a ConsList. |
static class |
ConsList.Nonempty<T>
The nonempty variant of a ConsList. |
| Constructor Summary | |
|---|---|
ConsList()
|
|
| Method Summary | ||
|---|---|---|
static
|
append(ConsList<? extends T> l1,
ConsList<? extends T> l2)
Append l2 to the end of l1 |
|
abstract
|
apply(ConsVisitor<? super T,? extends Ret> visitor)
|
|
int |
compositeHeight()
Get the maximum path length from this node to a leaf. |
|
int |
compositeSize()
Get the number of nodes in the tree rooted at this node. |
|
static
|
cons(T first,
ConsList<? extends T> rest)
Create a nonempty list (via ConsList()) |
|
static
|
empty()
Create an empty list (via ConsList.Empty.make()) |
|
static
|
filter(ConsList<? extends T> list,
Predicate<? super T> pred)
Filter the given list according to a predicate |
|
static
|
first(ConsList<? extends T> list)
Attempt to access the first of the given list (throws an exception in the empty case). |
|
boolean |
hasFixedSize()
Return true: cons lists have a fixed size. |
|
abstract boolean |
isEmpty()
Whether this is an empty ConsList. |
|
boolean |
isInfinite()
Return false: cons lists are not infinite. |
|
boolean |
isStatic()
Return true: cons lists are immutable. |
|
abstract java.util.Iterator<T> |
iterator()
|
|
static
|
map(ConsList<? extends S> list,
Lambda<? super S,? extends T> lambda)
Map the given list according to a lambda |
|
static
|
rest(ConsList<? extends T> list)
Attempt to access the rest of the given list (throws an exception in the empty case). |
|
static
|
reverse(ConsList<? extends T> list)
Reverse the given list |
|
static
|
singleton(T value)
Create a singleton nonempty list (via ConsList()) |
|
abstract int |
size()
Compute the size of the list. |
|
abstract int |
size(int bound)
Compute the size of the list, up to a given bound. |
|
| Methods inherited from class edu.rice.cs.plt.iter.AbstractIterable |
|---|
equals, hashCode, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ConsList()
| Method Detail |
|---|
public abstract <Ret> Ret apply(ConsVisitor<? super T,? extends Ret> visitor)
public abstract java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public abstract boolean isEmpty()
isEmpty in interface SizedIterable<T>public abstract int size()
size in interface SizedIterable<T>public abstract int size(int bound)
size in interface SizedIterable<T>bound - Maximum result. Assumed to be nonnegative.public boolean isInfinite()
false: cons lists are not infinite.
isInfinite in interface SizedIterable<T>public boolean hasFixedSize()
true: cons lists have a fixed size.
hasFixedSize in interface SizedIterable<T>public boolean isStatic()
true: cons lists are immutable.
isStatic in interface SizedIterable<T>public int compositeHeight()
Composite
compositeHeight in interface Compositepublic int compositeSize()
Composite
compositeSize in interface Compositepublic static <T> ConsList.Empty<T> empty()
ConsList.Empty.make())
public static <T> ConsList.Nonempty<T> cons(T first,
ConsList<? extends T> rest)
ConsList())
public static <T> ConsList.Nonempty<T> singleton(T value)
ConsList())
public static <T> T first(ConsList<? extends T> list)
public static <T> ConsList<? extends T> rest(ConsList<? extends T> list)
public static <T> ConsList<? extends T> reverse(ConsList<? extends T> list)
public static <T> ConsList<? extends T> append(ConsList<? extends T> l1,
ConsList<? extends T> l2)
l2 to the end of l1
public static <T> ConsList<? extends T> filter(ConsList<? extends T> list,
Predicate<? super T> pred)
public static <S,T> ConsList<? extends T> map(ConsList<? extends S> list,
Lambda<? super S,? extends T> lambda)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||