at.molindo.utils.collections
Class IteratorUtils

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

public class IteratorUtils
extends Object


Field Summary
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>
iterable(Iterator<T> iter)
           
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> Iterator<T>
skip(Iterator<T> iter, int skip)
          skips a given number of elements in iterator while there are available
 
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
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

next

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

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:

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:


Copyright © 2011 Molindo GmbH. All Rights Reserved.