at.molindo.utils.collections
Class IteratorUtils

java.lang.Object
  extended by at.molindo.utils.collections.IteratorUtils

public class IteratorUtils
extends Object


Field Summary
static Iterable<?> EMPTY_ITERABLE
           
static Iterator<?> EMPTY_ITERATOR
           
 
Method Summary
static
<T,C extends Collection<T>>
C
addAll(C collection, Iterator<T> iter)
          adds all elements from iter to collection
static
<T> Iterable<T>
cast(Class<T> cls, Iterable<?> iterable)
          a type safe cast for Iterable
static
<T> Iterable<T>
cast(Class<T> cls, Object[] list)
          type safe cast from any array to an Iterable
static
<T> Iterator<T>
empty()
          type save access to EMPTY_ITERATOR
static
<T> Iterable<T>
emptyIterable()
          type save access to EMPTY_ITERABLE
static boolean equals(Iterable<?> iterable1, Iterable<?> iterable2)
           
static boolean equals(Iterator<?> iter1, Iterator<?> iter2)
           
static
<T> Iterable<T>
filter(Iterable<T> iterable, Function<T,Boolean> filter)
           
static
<T> Iterator<T>
filter(Iterator<T> iter, Function<T,Boolean> filter)
           
static
<T> T
first(Iterable<T> iter)
           
static
<T> Iterable<T>
iterable(Iterator<T> iter)
           
static
<T> Iterator<T>
iterator(Iterable<T> iterable)
           
static
<T> Iterable<Iterator<T>>
iterators(Iterable<? extends Iterable<T>> iterables)
          transforms an Iterable of Iterables to an Iterable of Iterators
static
<T> Iterator<Iterator<T>>
iterators(Iterator<? extends Iterable<T>> iterables)
          transforms an Iterator of Iterables to an Iterator of Iterators
static
<T> ArrayList<T>
list(Iterable<T> iter)
           
static
<T> ArrayList<T>
list(Iterable<T> iter, int initialCapacity)
           
static
<T> ArrayList<T>
list(Iterator<T> iter)
           
static
<T> ArrayList<T>
list(Iterator<T> iter, int initialCapacity)
           
static
<T> Iterator<T>
max(Iterator<T> iter, int max)
          don't return more elements than given by max
static
<T> T
next(Iterator<T> iter)
           
static
<T> Iterable<T>
notNull(Iterable<T> iter)
           
static
<T> Iterator<T>
notNull(Iterator<T> iter)
           
static
<T> Iterator<T>
object(T o)
           
static
<T> Iterable<T>
readOnly(Iterable<T> iter)
           
static
<T> Iterator<T>
readOnly(Iterator<T> iter)
           
static
<T> Iterator<T>
skip(Iterator<T> iter, int skip)
          skips a given number of elements in iterator while there are available
static
<F,T> Iterable<T>
transform(Iterable<? extends F> iterable, Function<F,T> f)
           
static
<F,T> Iterator<T>
transform(Iterator<? extends F> iter, Function<F,T> f)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ITERATOR

public static final Iterator<?> EMPTY_ITERATOR

EMPTY_ITERABLE

public static final Iterable<?> EMPTY_ITERABLE
Method Detail

iterable

public static <T> Iterable<T> iterable(Iterator<T> iter)
Type Parameters:
T -
Parameters:
iter -
Returns:
an Iterable that alway returns the passed Iterator instance

iterator

public static <T> Iterator<T> iterator(Iterable<T> iterable)
Type Parameters:
T -
Parameters:
iterable -
Returns:
Iterable.iterator() or EMPTY_ITERATOR if null

iterators

public static <T> Iterator<Iterator<T>> iterators(Iterator<? extends Iterable<T>> iterables)
transforms an Iterator of Iterables to an Iterator of Iterators


iterators

public static <T> Iterable<Iterator<T>> iterators(Iterable<? extends Iterable<T>> iterables)
transforms an Iterable of Iterables to an Iterable of Iterators


next

public static <T> T next(Iterator<T> iter)
Type Parameters:
T -
Parameters:
iter -
Returns:
the next element if available, null otherwise

first

public static <T> T first(Iterable<T> iter)
Type Parameters:
T -
Parameters:
iter -
Returns:
the first element if available, null otherwise

list

public static <T> ArrayList<T> list(Iterable<T> iter)
Type Parameters:
T -
Parameters:
iter -
Returns:
an ArrayList containing all elements

list

public static <T> ArrayList<T> list(Iterable<T> iter,
                                    int initialCapacity)
Type Parameters:
T -
Parameters:
iter -
Returns:
an ArrayList containing all elements

list

public static <T> ArrayList<T> list(Iterator<T> iter)
Type Parameters:
T -
Parameters:
iter -
Returns:
an ArrayList containing all elements

list

public static <T> ArrayList<T> list(Iterator<T> iter,
                                    int initialCapacity)
Type Parameters:
T -
Parameters:
iter -
Returns:
an ArrayList containing all elements

addAll

public static <T,C extends Collection<T>> C addAll(C collection,
                                                   Iterator<T> iter)
adds all elements from iter to collection

Type Parameters:
T -
C -
Parameters:
collection -
iter -
Returns:

empty

public static <T> Iterator<T> empty()
type save access to EMPTY_ITERATOR

Type Parameters:
T -
Returns:

emptyIterable

public static <T> Iterable<T> emptyIterable()
type save access to EMPTY_ITERABLE

Type Parameters:
T -
Returns:

notNull

public static <T> Iterator<T> notNull(Iterator<T> iter)

notNull

public static <T> Iterable<T> notNull(Iterable<T> iter)

cast

public static <T> Iterable<T> cast(Class<T> cls,
                                   Object[] list)
type safe cast from any array to an Iterable

Type Parameters:
T -
Parameters:
cls -
list -
Returns:

cast

public static <T> Iterable<T> cast(Class<T> cls,
                                   Iterable<?> iterable)
a type safe cast for Iterable

Type Parameters:
T -
Parameters:
cls -
iterable -
Returns:

skip

public static <T> Iterator<T> skip(Iterator<T> iter,
                                   int skip)
skips a given number of elements in iterator while there are available

Type Parameters:
T -
Parameters:
iter -
skip -
Returns:

max

public static <T> Iterator<T> max(Iterator<T> iter,
                                  int max)
don't return more elements than given by max

Type Parameters:
T -
Parameters:
iter -
max -
Returns:

object

public static <T> Iterator<T> object(T o)

filter

public static <T> Iterable<T> filter(Iterable<T> iterable,
                                     Function<T,Boolean> filter)

filter

public static <T> Iterator<T> filter(Iterator<T> iter,
                                     Function<T,Boolean> filter)
Type Parameters:
T -
Parameters:
iter -
filter - function that returns true if object is allowed
Returns:

transform

public static <F,T> Iterator<T> transform(Iterator<? extends F> iter,
                                          Function<F,T> f)

transform

public static <F,T> Iterable<T> transform(Iterable<? extends F> iterable,
                                          Function<F,T> f)

equals

public static boolean equals(Iterable<?> iterable1,
                             Iterable<?> iterable2)

equals

public static boolean equals(Iterator<?> iter1,
                             Iterator<?> iter2)

readOnly

public static <T> Iterable<T> readOnly(@Nonnull
                                       Iterable<T> iter)

readOnly

public static <T> Iterator<T> readOnly(@Nonnull
                                       Iterator<T> iter)


Copyright © 2013 Molindo GmbH. All Rights Reserved.