com.myjavatools.lib.foundation
Class Iterators

java.lang.Object
  extended by com.myjavatools.lib.foundation.Iterators

public class Iterators
extends java.lang.Object

Iterators is a utility class that contains static methods for iterators

Since:
5.0
Version:
5.0, 01/29/05
See Also:
Collection, Iterator, Filter

Nested Class Summary
static class Iterators.EmptyIterator<T>
          EmptyIterator is a helper class that does not contain any elements and throws an exception when next() is called.
 
Constructor Summary
Iterators()
           
 
Method Summary
static
<T> java.util.Collection<T>
cat(java.util.Collection<? extends T>... elements)
          Concatenates vararg Collections into one List
static
<T> java.util.Iterator<T>
cat(java.lang.Iterable<? extends java.util.Iterator<T>> outerLoop)
          Creates an Iterator view of an Iterable consisting of Iterators
static
<X> java.lang.Iterable<X>
cat(java.lang.Iterable<? extends X>... elements)
          Concatenates vararg Iterables into one List
static
<T> java.util.Iterator<T>
cat(java.util.Iterator<T>... components)
          Creates an Iterator view of a sequence of Iterators
static java.lang.Iterable<java.lang.Character> chars(java.lang.CharSequence sequence)
          returns an iterable good for using in a foreach loop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iterators

public Iterators()
Method Detail

cat

public static <T> java.util.Iterator<T> cat(java.lang.Iterable<? extends java.util.Iterator<T>> outerLoop)
Creates an Iterator view of an Iterable consisting of Iterators

Parameters:
outerLoop - Iterable <? extends Iterator<T>> source iterators
Returns:
Iterator a compound iterator that scans the first iterator from the sequence, then the second, etc. Can be used with varargs: cat(iterator1, iterator2, iterator3) and with arrays: cat(iterators[]).

Example:


 List list1 = Arrays.asList(new String[] {"One", "Two", "Three"});
 List list2 = Arrays.asList(new String[] {"Four", "Five", "Six"});
 List list3 = Arrays.asList(new String[] {"One", "Two", "Three", "Four", "Five", "Six"}
 cat(Arrays.asList(new Iterator {list1.iterator(), list2.iterator()}))
returns the same as list3.iterator().


cat

public static <T> java.util.Iterator<T> cat(java.util.Iterator<T>... components)
Creates an Iterator view of a sequence of Iterators

Parameters:
components - Iterator[] source iterators
Returns:
Iterator a compound iterator that scans the first iterator from the sequence, then the second, etc. Can be used with varargs: cat(iterator1, iterator2, iterator3) and with arrays: cat(iterators[]).

Example:


 List list1 = Arrays.asList(new String[] {"One", "Two", "Three"});
 List list2 = Arrays.asList(new String[] {"Four", "Five", "Six"});
 List list3 = Arrays.asList(new String[] {"One", "Two", "Three", "Four", "Five", "Six"}
 cat(list1.iterator(), list2.iterator())
returns the same as list3.iterator().


cat

public static <X> java.lang.Iterable<X> cat(java.lang.Iterable<? extends X>... elements)
Concatenates vararg Iterables into one List

Parameters:
elements - Iterable<? extends X>...
Returns:
an Iterable view that has elements of the component Iterables.

Example:
  • cat(Arrays.asList(new String[] {"a", "b", "c"}), Arrays.asList(new String[] {"b", "a", "d"})) returns the same Iterable as Arrays.asList(new String[] {"a", "b", "c", "b", "a", "d"}).

  • cat

    public static <T> java.util.Collection<T> cat(java.util.Collection<? extends T>... elements)
    Concatenates vararg Collections into one List

    Parameters:
    elements - Collection<? extends T>...
    Returns:
    an Collection view that has elements of the component Collections.

    Example:
  • cat(Arrays.asList(new String[] {"a", "b", "c"}), Arrays.asList(new String[] {"b", "a", "d"})) returns the same Collection as Arrays.asList(new String[] {"a", "b", "c", "b", "a", "d"}).

  • chars

    public static java.lang.Iterable<java.lang.Character> chars(java.lang.CharSequence sequence)
    returns an iterable good for using in a foreach loop

    Parameters:
    sequence - CharSequence to scan
    Returns:
    Iterable<Character>

    Example:
  • for (char c : chars("this is an example"){ System.out.println("Character " + c); }