fi.iki.juri.collections
Class JIterTools

java.lang.Object
  extended by fi.iki.juri.collections.JIterTools

public class JIterTools
extends java.lang.Object


Constructor Summary
JIterTools()
           
 
Method Summary
static
<T> java.lang.Iterable<EnumeratedItem<T>>
enumerate(java.lang.Iterable<T> iterable)
          An Iterable-based version of enumerate(Iterator).
static
<T> java.lang.Iterable<EnumeratedItem<T>>
enumerate(java.lang.Iterable<T> iterable, int start)
          An Iterable-based version of enumerate(Iterator, int).
static
<T> java.util.Iterator<EnumeratedItem<T>>
enumerate(java.util.Iterator<T> iterator)
          Transforms the Iterator (a b c d ...) to ((0 a) (1 b) (2 c) (3 d) ...).
static
<T> java.util.Iterator<EnumeratedItem<T>>
enumerate(java.util.Iterator<T> iterator, int start)
          Transforms the Iterator (a b c d ...) to ((start a) (start+1 b) (start+2 c) (start+3 d) ...).
static
<T> java.lang.Iterable<java.util.Collection<T>>
zip(java.util.Collection<java.lang.Iterable<T>> iterables)
          Iterable-based counterpart to zip(Collection).
static
<T> java.util.Iterator<java.util.Collection<T>>
zip(java.util.Collection<java.util.Iterator<T>> iterators)
          Zip up multiple iterators.
static
<T> java.lang.Iterable<java.util.Collection<T>>
zip(java.lang.Iterable<T>... iterables)
          Iterable-based counterpart to zip(Iterator...).
static
<T> java.util.Iterator<java.util.Collection<T>>
zip(java.util.Iterator<T>... iterators)
          Vararg-based version of zip(Collection)
static
<T> java.lang.Iterable<java.util.Collection<T>>
zipFill(java.util.Collection<IterableAndFiller<T>> iterables)
           
static
<T> java.util.Iterator<java.util.Collection<T>>
zipFill(java.util.Collection<IteratorAndFiller<T>> itfillers)
          Zip up multiple Iterators.
static
<T> java.util.Iterator<java.util.Collection<T>>
zipFill(IteratorAndFiller<T>... itfillers)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JIterTools

public JIterTools()
Method Detail

zip

public static <T> java.util.Iterator<java.util.Collection<T>> zip(java.util.Collection<java.util.Iterator<T>> iterators)
Zip up multiple iterators. ((a b c) (d e f)) becomes ((a d) (b e) (c f)). Stops when any of the Iteratorss reports it has no more items.

Parameters:
iterators - the Iterators to zip up
Returns:
an Iterator of Collections, where the nth item in the mth Collection is the mth item in the nth Iterator passed in as a parameter.

zip

public static <T> java.util.Iterator<java.util.Collection<T>> zip(java.util.Iterator<T>... iterators)
Vararg-based version of zip(Collection)


zip

public static <T> java.lang.Iterable<java.util.Collection<T>> zip(java.util.Collection<java.lang.Iterable<T>> iterables)
Iterable-based counterpart to zip(Collection).


zip

public static <T> java.lang.Iterable<java.util.Collection<T>> zip(java.lang.Iterable<T>... iterables)
Iterable-based counterpart to zip(Iterator...).


zipFill

public static <T> java.util.Iterator<java.util.Collection<T>> zipFill(java.util.Collection<IteratorAndFiller<T>> itfillers)
Zip up multiple Iterators. ((a b c) (d e f)) becomes ((a d) (b e) (c f)). Stops when all of the Iterators report they have no more items. Uses the function passed in the IteratorAndFiller object to acquire filler data for an exhausted Iterator.

Parameters:
itfillers - the Iterators to zip up and the corresponding filler functions
Returns:
an Iterator of Collections, where the nth item in the mth Collection is the mth item in the nth Iterator passed in as a parameter or the result of calling the corresponding FillerFunction

zipFill

public static <T> java.util.Iterator<java.util.Collection<T>> zipFill(IteratorAndFiller<T>... itfillers)
See Also:
zipFill(Collection)

zipFill

public static <T> java.lang.Iterable<java.util.Collection<T>> zipFill(java.util.Collection<IterableAndFiller<T>> iterables)

enumerate

public static <T> java.util.Iterator<EnumeratedItem<T>> enumerate(java.util.Iterator<T> iterator)
Transforms the Iterator (a b c d ...) to ((0 a) (1 b) (2 c) (3 d) ...).

Parameters:
iterator - the objects whose contents should be enumerated.
Returns:
an Iterator object containing the enumerated items of parameter iterator.
See Also:
if you want to specify the starting index.

enumerate

public static <T> java.util.Iterator<EnumeratedItem<T>> enumerate(java.util.Iterator<T> iterator,
                                                                  int start)
Transforms the Iterator (a b c d ...) to ((start a) (start+1 b) (start+2 c) (start+3 d) ...).

Type Parameters:
T -
Parameters:
iterator - the objects whose contents should be enumerated.
start - the number to start the enumeration with.
Returns:
an Iterator object containing the enumerated items of parameter iterator.

enumerate

public static <T> java.lang.Iterable<EnumeratedItem<T>> enumerate(java.lang.Iterable<T> iterable)
An Iterable-based version of enumerate(Iterator).


enumerate

public static <T> java.lang.Iterable<EnumeratedItem<T>> enumerate(java.lang.Iterable<T> iterable,
                                                                  int start)
An Iterable-based version of enumerate(Iterator, int).