|
||||||||||
| 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.iter.TruncatedIterable<T>
edu.rice.cs.plt.iter.FiniteSequenceIterable<T>
public class FiniteSequenceIterable<T>
An iterable representing a finite sequence. The sequence is defined by an initial
value and a successor function (described by a Lambda), along with a size that
truncates the (otherwise infinite) list. This is a trivial extension to
TruncatedIterable, but does add optimized implementations of size() and
hasFixedSize() (since the nature of the nested iterable is known).
| Field Summary |
|---|
| Fields inherited from class edu.rice.cs.plt.iter.TruncatedIterable |
|---|
_size |
| Constructor Summary | |
|---|---|
FiniteSequenceIterable(T initial,
Lambda<? super T,? extends T> successor,
int size)
|
|
| Method Summary | ||
|---|---|---|
boolean |
hasFixedSize()
true if this iterable is known to have a fixed size. |
|
boolean |
isStatic()
Always false: results of a lambda may be arbitrary. |
|
static
|
make(T initial,
Lambda<? super T,? extends T> successor,
int size)
Call the constructor (allows T to be inferred) |
|
static
|
makeCopies(T value,
int copies)
Create a sequence containing copies instances of the given value. |
|
static FiniteSequenceIterable<Integer> |
makeIntegerSequence(int start,
int end)
Create a simple sequence containing the numbers between start and end
(inclusive). |
|
static
|
makeSnapshot(T initial,
Lambda<? super T,? extends T> successor,
int size)
Create a FiniteSequenceIterable and wrap it in a SnapshotIterable, forcing
immediate evaluation of the sequence. |
|
int |
size()
Return size, unless the nested iterable is smaller than size; in that
case, returns the iterable's size. |
|
int |
size(int bound)
Compute the number of elements in the iterable, up to the given bound. |
|
| Methods inherited from class edu.rice.cs.plt.iter.TruncatedIterable |
|---|
compositeHeight, compositeSize, isEmpty, isInfinite, iterator, make, makeSnapshot |
| 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 FiniteSequenceIterable(T initial,
Lambda<? super T,? extends T> successor,
int size)
initial - The first value in the sequencesuccessor - A function that, given the nth sequence value, produces the n+1st valuesize - The number of elements in the sequence
IllegalArgumentException - If size is less than 0| Method Detail |
|---|
public int size()
TruncatedIterablesize, unless the nested iterable is smaller than size; in that
case, returns the iterable's size.
size in interface SizedIterable<T>size in class TruncatedIterable<T>public int size(int bound)
SizedIterablebound, bound is returned.
size in interface SizedIterable<T>size in class TruncatedIterable<T>bound - Maximum result. Assumed to be nonnegative.public boolean hasFixedSize()
SizedIterabletrue if this iterable is known to have a fixed size. This is the case if the iterable is immutable,
or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it
is guaranteed to never become finite.
hasFixedSize in interface SizedIterable<T>hasFixedSize in class TruncatedIterable<T>public boolean isStatic()
isStatic in interface SizedIterable<T>isStatic in class TruncatedIterable<T>
public static <T> FiniteSequenceIterable<T> make(T initial,
Lambda<? super T,? extends T> successor,
int size)
T to be inferred)
public static <T> SnapshotIterable<T> makeSnapshot(T initial,
Lambda<? super T,? extends T> successor,
int size)
FiniteSequenceIterable and wrap it in a SnapshotIterable, forcing
immediate evaluation of the sequence.
public static FiniteSequenceIterable<Integer> makeIntegerSequence(int start,
int end)
start and end
(inclusive). start may be less than or greater than end (or even
equal to it); the resulting iterator will increment or decrement as necessary.
public static <T> FiniteSequenceIterable<T> makeCopies(T value,
int copies)
copies instances of the given value.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||