jpaul.DataStructs
Class CompoundIterable<A,B>

java.lang.Object
  extended by jpaul.DataStructs.CompoundIterable<A,B>
All Implemented Interfaces:
java.lang.Iterable<B>

public class CompoundIterable<A,B>
extends java.lang.Object
implements java.lang.Iterable<B>

CompoundIterable allows the construction of an Iterable by merging several smaller Iterables. Given an iterable with elements a0, a1, ..., ak, and a function f that transforms each ai into an iterable, the CompoundIterable will contain all elements from f(a0), followed by all the elements from f(a1) and so on.

The elements of a CompoundIterable are generated lazily, as we iterate over them. This tehcniqued is better than eager iteration in the case when (1) f is simple; (2) the original Iterable changes dynamically; (3) the number of traversals is small; or (3) the number of elements is very large.

Version:
$Id: CompoundIterable.java,v 1.3 2005/08/10 23:22:28 salcianu Exp $
Author:
Alexandru Salcianu - salcianu@alum.mit.edu

Constructor Summary
CompoundIterable(java.lang.Iterable<A> collA, Function<A,java.lang.Iterable<B>> a2iter)
          Creates a CompoundIterable.
 
Method Summary
 java.util.Iterator<B> iterator()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompoundIterable

public CompoundIterable(java.lang.Iterable<A> collA,
                        Function<A,java.lang.Iterable<B>> a2iter)
Creates a CompoundIterable.

Parameters:
collA - An iterable of elements of type A.
a2iter - A function that transforms each element from collA into an Iterable of Bs.
Method Detail

iterator

public java.util.Iterator<B> iterator()
Specified by:
iterator in interface java.lang.Iterable<B>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu