com.myjavatools.lib.foundation
Class Iterators

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

public abstract class Iterators
extends java.lang.Object

Iterators is a utility class that contains static methods for iterators

Since:
5.0
Version:
6.0 05/04/06
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 Collection
static
<T> java.util.Collection<T>
cat(java.util.Collection<java.util.Collection<? extends T>> elements)
          Concatenates a collection of collections into one Collection
static
<T> java.util.Iterator<T>
cat(java.lang.Iterable<? extends java.util.Iterator<? extends T>> outerLoop)
          Creates an Iterator view of an Iterable consisting of Iterators
static
<T> java.lang.Iterable<T>
cat(java.lang.Iterable<? extends T>... elements)
          Concatenates vararg Iterables into one List
static
<T> java.util.Iterator<T>
cat(java.util.Iterator<? extends T>... components)
          Creates an Iterator view of a sequence of Iterators
static java.lang.Iterable<java.lang.Character> chars(java.lang.CharSequence sequence)
          Deprecated. This iterable has been moved to Strings
 
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<? extends T>> outerLoop)
Creates an Iterator view of an Iterable consisting of Iterators

Parameters:
outerLoop - Iterable <? extends Iterator<? extends 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<? extends T>... components)
Creates an Iterator view of a sequence of Iterators

Parameters:
components - Iterator<? extends 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(list1.iterator(), list2.iterator())
returns the same as list3.iterator().


cat

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

Parameters:
elements - Iterable<? extends T>...
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 Collection

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

    Example:
  • cat(Arrays.asList("a", "b", "c"), Arrays.asList("b", "a", "d")) returns the same Collection as Arrays.asList("a", "b", "c", "b", "a", "d").

  • cat

    public static <T> java.util.Collection<T> cat(java.util.Collection<java.util.Collection<? extends T>> elements)
    Concatenates a collection of collections into one Collection

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

    Example:
  • cat(Arrays.asList(Arrays.asList("a", "b", "c"), Arrays.asList("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)
    Deprecated. This iterable has been moved to Strings

    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); }