edu.rice.cs.plt.iter
Class ComposedIterable<T>

java.lang.Object
  extended by edu.rice.cs.plt.iter.AbstractIterable<T>
      extended by edu.rice.cs.plt.iter.ComposedIterable<T>
All Implemented Interfaces:
OptimizedLastIterable<T>, SizedIterable<T>, Composite, Serializable, Iterable<T>

public class ComposedIterable<T>
extends AbstractIterable<T>
implements SizedIterable<T>, OptimizedLastIterable<T>, Composite, Serializable

Defines an iterable by composing two other iterables (or a value with an iterable). Subsequent changes to the input lists will be reflected.

See Also:
Serialized Form

Constructor Summary
ComposedIterable(Iterable<? extends T> i1, Iterable<? extends T> i2)
          The result contains i1's elements followed by i2's elements.
ComposedIterable(Iterable<? extends T> i1, T v2)
          The result contains i1's elements followed by v2
ComposedIterable(T v1, Iterable<? extends T> i2)
          The result contains v1 followed by i2's elements
 
Method Summary
 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.
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 boolean isEmpty()
          Whether the iterable does not contain any elements.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 ComposedIterator<T> iterator()
           
 T last()
          Determine the last value in the iterable.
static
<T> ComposedIterable<T>
make(Iterable<? extends T> i1, Iterable<? extends T> i2)
          Call the constructor (allows T to be inferred)
static
<T> ComposedIterable<T>
make(Iterable<? extends T> i1, T v2)
          Call the constructor (allows T to be inferred)
static
<T> ComposedIterable<T>
make(T v1, Iterable<? extends T> i2)
          Call the constructor (allows T to be inferred)
 int size()
          Compute the number of elements in the iterable.
 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.AbstractIterable
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComposedIterable

public ComposedIterable(Iterable<? extends T> i1,
                        Iterable<? extends T> i2)
The result contains i1's elements followed by i2's elements.


ComposedIterable

public ComposedIterable(T v1,
                        Iterable<? extends T> i2)
The result contains v1 followed by i2's elements


ComposedIterable

public ComposedIterable(Iterable<? extends T> i1,
                        T v2)
The result contains i1's elements followed by v2

Method Detail

iterator

public ComposedIterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

compositeHeight

public int compositeHeight()
Description copied from interface: Composite
Get the maximum path length from this node to a leaf.

Specified by:
compositeHeight in interface Composite

compositeSize

public int compositeSize()
Description copied from interface: Composite
Get the number of nodes in the tree rooted at this node. Always 1 or greater.

Specified by:
compositeSize in interface Composite

isEmpty

public boolean isEmpty()
Description copied from interface: SizedIterable
Whether the iterable does not contain any elements.

Specified by:
isEmpty in interface SizedIterable<T>

size

public int size()
Description copied from interface: SizedIterable
Compute the number of elements in the iterable. If the size is infinite or too large to be represented as an int, Integer.MAX_VALUE should be returned. Otherwise, next() may be safely invoked on the iterator exactly this number of times.

Specified by:
size in interface SizedIterable<T>

size

public int size(int bound)
Description copied from interface: SizedIterable
Compute the number of elements in the iterable, up to the given bound. If the size is infinite or greater than bound, bound is returned.

Specified by:
size in interface SizedIterable<T>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

public boolean isInfinite()
Description copied from interface: SizedIterable
true if the iterable is known to have infinite size. If true, an iterator over the iterable in its current state will never return false from hasNext().

Specified by:
isInfinite in interface SizedIterable<T>

hasFixedSize

public boolean hasFixedSize()
Description copied from interface: SizedIterable
true 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.

Specified by:
hasFixedSize in interface SizedIterable<T>

isStatic

public boolean isStatic()
Description copied from interface: SizedIterable
true if this iterable is unchanging. This implies that hasFixedSize() is true, and that iterator() will always return the same (either == or equal() and immutable) elements in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if two objects are equal, they will never become inequal, and vice versa.)

Specified by:
isStatic in interface SizedIterable<T>

last

public T last()
Determine the last value in the iterable. This implementation will usually be faster than the general approach of iterating through the entire list -- for a balanced ComposedIterable tree, it takes log(n) time; if the right subtree is a singleton, the result is computed trivially. (Note that the approach used avoids recursion in order to prevent a stack overflow.)

Specified by:
last in interface OptimizedLastIterable<T>

make

public static <T> ComposedIterable<T> make(Iterable<? extends T> i1,
                                           Iterable<? extends T> i2)
Call the constructor (allows T to be inferred)


make

public static <T> ComposedIterable<T> make(T v1,
                                           Iterable<? extends T> i2)
Call the constructor (allows T to be inferred)


make

public static <T> ComposedIterable<T> make(Iterable<? extends T> i1,
                                           T v2)
Call the constructor (allows T to be inferred)