org.jjoost.util
Class Iters

java.lang.Object
  extended by org.jjoost.util.Iters

public class Iters
extends java.lang.Object

A class declaring useful methods for working with Iterator and Iterable objects

Author:
b.elliottsmith

Constructor Summary
Iters()
           
 
Method Summary
static
<E> ConcatIterable<E>
concat(java.lang.Iterable<? extends java.lang.Iterable<E>> a)
          Lazily concatenates the provided Iterable objects.
static
<E> ConcatIterable<E>
concat(java.lang.Iterable<E>... a)
          Lazily concatenates the provided Iterable objects.
static
<E> ConcatIterable<E>
concat(java.lang.Iterable<E> a, java.lang.Iterable<E> b)
          Lazily concatenates the two provided Iterable objects.
static
<E> ConcatIterator<E>
concat(java.util.Iterator<? extends java.util.Iterator<E>> a)
          Lazily concatenates the provided Iterator objects.
static
<E> boolean
contains(E find, java.lang.Iterable<E> iter)
          Returns a boolean indicating if the provided Iterable contains an element equal to the provided object, as determined by regular Object equality (Equalities.object()).
static
<E> boolean
contains(E find, java.util.Iterator<E> iter)
          Returns a boolean indicating if the provided Iterator contains an element equal to the provided object, as determined by regular Object equality (Equalities.object()).
static
<E> boolean
contains(Equality<? super E> eq, E find, java.lang.Iterable<E> iter)
          Returns a boolean indicating if the provided Iterable contains an element equal to the provided object, as determined by the provided Equality.
static
<E> boolean
contains(Equality<? super E> eq, E find, java.util.Iterator<E> iter)
          Returns a boolean indicating if the provided Iterator contains an element equal to the provided object, as determined by the provided Equality.
static
<E> int
count(E find, java.lang.Iterable<E> iter)
          Returns an int representing the number of occurrences, in the provided Iterable, of elements equal to the provided object, as determined by regular Object equality (Equalities.object()).
static
<E> int
count(E find, java.util.Iterator<E> iter)
          Returns an int representing the number of occurrences, in the provided Iterator, of elements equal to the provided object, as determined by regular Object equality (Equalities.object()).
static
<E> int
count(Equality<? super E> eq, E find, java.lang.Iterable<E> iter)
          Returns an int representing the number of occurrences, in the provided Iterable, of elements equal to the provided object, as determined by the provided Equality.
static
<E> int
count(Equality<? super E> eq, E find, java.util.Iterator<E> iter)
          Returns an int representing the number of occurrences, in the provided Iterator, of elements equal to the provided object, as determined by the provided Equality.
static int count(java.lang.Iterable<?> iter)
          count the items in the provided Iterable by creating an Iterator from it and consuming every element
static int count(java.util.Iterator<?> iter)
          counts the items in the provided Iterator by fully exhausting it
static
<E> java.util.Iterator<E>
destroyAsConsumed(java.util.Iterator<E> iter)
          Return an Iterator that wraps the provided Iterator, and automatically calls remove() after every successful call of next()
static
<E> ClosableIterator<E>
drop(ClosableIterator<E> iter, int count)
          Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument
static
<E> ClosableIterator<E>
drop(int count, ClosableIterator<E> iter)
          Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument
static
<E> DropIterable<E>
drop(int count, java.lang.Iterable<E> iter)
          Returns a new Iterable that returns all but the first count elements of the supplied Iterable (or none of them if there are fewer).
static
<E> java.util.Iterator<E>
drop(int count, java.util.Iterator<E> iter)
          Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument
static
<E> DropIterable<E>
drop(java.lang.Iterable<E> iter, int count)
          Returns a new Iterable that returns all but the first count elements of the supplied Iterable (or none of them if there are fewer).
static
<E> java.util.Iterator<E>
drop(java.util.Iterator<E> iter, int count)
          Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument
static
<E> java.util.List<E>
drop(java.util.List<E> list, int count)
          Returns a List that represents all but the first count elements of the supplied List (or none of them if there are fewer).
static
<E> java.lang.Iterable<E>
emptyIterable()
          Return an Iterator which contains no values
static
<E> java.util.Iterator<E>
emptyIterator()
          Return an Iterator which contains no values
static
<E> boolean
equal(Equality<? super E> eq, java.util.Iterator<? extends E> a, java.util.Iterator<? extends E> b)
          Returns a boolean indicating if the two provided Iterators are "equal", using the provided Equality.
static boolean equal(java.util.Iterator<?> a, java.util.Iterator<?> b)
          Returns a boolean indicating if the two provided Iterators are "equal", using regular Object equality (Equalities.object()).
static
<E> HeadClosableIterator<E>
head(ClosableIterator<E> iter, int count)
          Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)
static
<E> HeadClosableIterator<E>
head(int count, ClosableIterator<E> iter)
          Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)
static
<E> HeadIterable<E>
head(int count, java.lang.Iterable<E> iter)
          Returns a new Iterable that returns the first count elements of the supplied Iterable (or all of them if that is fewer)
static
<E> HeadIterator<E>
head(int count, java.util.Iterator<E> iter)
          Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)
static
<E> HeadIterable<E>
head(java.lang.Iterable<E> iter, int count)
          Returns a new Iterable that returns the first count elements of the supplied Iterable (or all of them if that is fewer)
static
<E> HeadIterator<E>
head(java.util.Iterator<E> iter, int count)
          Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)
static
<E> java.util.List<E>
head(java.util.List<E> list, int count)
          Returns a new List that returns the first count elements of the supplied List (or all of them if that is fewer)
static
<E> java.util.Iterator<E>
iterator(E[] array)
          convert the supplied array into an Iterator
static
<E> java.util.Iterator<E>
iterator(E[] array, int count)
          convert the supplied array into an Iterator
static
<E> java.util.Iterator<E>
iterator(E[] array, int lb, int ub)
          convert the supplied array into an Iterator
static
<E> java.util.Iterator<E>
iterator(java.util.Enumeration<E> enumeration)
          convert the supplied Enumeration into an Iterator
static
<E> java.lang.Iterable<E>
onceIterable(java.util.Iterator<E> iter)
          Create a one-shot Iterable from the supplied Iterator
static
<E> java.util.List<E>
tail(java.util.List<E> list, int count)
          Returns a List that represents the last count elements of the supplied List (or all of them if there are fewer).
static java.lang.Object[] toArray(java.lang.Iterable<?> iter)
          Create an Object[] from the supplied Iterable
static
<T> T[]
toArray(java.lang.Iterable<?> iter, java.lang.Class<T> clazz)
          Copy the contents of the provided Iterable into an array of the provided type.
static
<T> T[]
toArray(java.lang.Iterable<?> iter, T[] a)
          Copy the contents of the provided Iterable into the provided array; if the array is not large enough a new one will be initialised and returned.
static java.lang.Object[] toArray(java.util.Iterator<?> iter)
          Create an Object[] from the supplied Iterator.
static
<T> T[]
toArray(java.util.Iterator<?> iter, java.lang.Class<T> clazz)
          Copy the contents of the provided Iterator into an array of the provided type.
static
<T> T[]
toArray(java.util.Iterator<?> iter, T[] a)
          Copy the contents of the provided Iterator into the provided array; if the array is not large enough a new one will be initialised and returned.
static
<E> java.util.List<E>
toList(java.lang.Iterable<E> iter)
          Create an Arraylist from the supplied Iterable
static
<E> java.util.List<E>
toList(java.util.Iterator<E> iter)
          Create an Arraylist from the supplied Iterator.
static
<E> void
toList(java.util.Iterator<E> iter, java.util.List<E> list)
          Exhaust the provided Iterator, copying its contents into the provided List
static java.lang.String toString(java.lang.Iterable<?> iter)
          Returns a string representation of the argument of the form produced by java.util collections
static java.lang.String toString(java.lang.Iterable<?> iter, java.lang.String delimiter)
          Concatenates the elements of the provided Iterable using the provided delimiter
static java.lang.String toString(java.util.Iterator<?> iter)
          Returns a string representation of the argument of the form produced by java.util collections.
static java.lang.String toString(java.util.Iterator<?> iter, java.lang.String delimiter)
          Concatenates the elements of the provided Iterator using the provided delimiter.
static ClosableIterator<java.lang.String> toStrings(ClosableIterator<?> iter, boolean replaceNulls)
          Lazily convert the provided Iterator into an Iterator of type String, by calling the toString() method on each item.
static java.lang.Iterable<java.lang.String> toStrings(java.lang.Iterable<?> iter, boolean replaceNulls)
          Lazily convert the provided Iterable into an Iterable of type String, by calling the toString() method on each item.
static java.util.Iterator<java.lang.String> toStrings(java.util.Iterator<?> iter, boolean replaceNulls)
          Lazily convert the provided Iterator into an Iterator of type String, by calling the toString() method on each item.
static java.util.List<java.lang.String> toStrings(java.util.List<?> list, boolean replaceNulls)
          Eagerly convert the provided List into a List of type String, by calling the toString() method on each item.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iters

public Iters()
Method Detail

emptyIterator

public static <E> java.util.Iterator<E> emptyIterator()
Return an Iterator which contains no values

Returns:
an Iterator which contains no values

emptyIterable

public static <E> java.lang.Iterable<E> emptyIterable()
Return an Iterator which contains no values

Returns:
an Iterator which contains no values

iterator

public static <E> java.util.Iterator<E> iterator(E[] array)
convert the supplied array into an Iterator

Parameters:
array - the array to wrap
Returns:
an Iterator representing the provided array

iterator

public static <E> java.util.Iterator<E> iterator(E[] array,
                                                 int count)
convert the supplied array into an Iterator

Parameters:
array - the array to wrap
count - the number of elements to use from the array, beginning at index 0
Returns:
an Iterator representing the first count elements of the array

iterator

public static <E> java.util.Iterator<E> iterator(E[] array,
                                                 int lb,
                                                 int ub)
convert the supplied array into an Iterator

Parameters:
array - array to wrap
lb - the first index to use from the array
ub - the last index to use from the array
Returns:
an Iterator representing the elements of the provided array from index lb (incl) to ub (excl)

iterator

public static <E> java.util.Iterator<E> iterator(java.util.Enumeration<E> enumeration)
convert the supplied Enumeration into an Iterator

Parameters:
enumeration - an Enumeration
Returns:
an Iterator wrapping the provided Enumeration

count

public static int count(java.lang.Iterable<?> iter)
count the items in the provided Iterable by creating an Iterator from it and consuming every element

Parameters:
iter - An Iterable
Returns:
the number of elements in the provided Iterable

count

public static int count(java.util.Iterator<?> iter)
counts the items in the provided Iterator by fully exhausting it

Parameters:
iter - an Iterator
Returns:
the number of elements in the provided Iterator

equal

public static boolean equal(java.util.Iterator<?> a,
                            java.util.Iterator<?> b)
Returns a boolean indicating if the two provided Iterators are "equal", using regular Object equality (Equalities.object()). The ordering of the elements is important to this method; i.e., it confirms that the same element occurs in the same position in both iterators.

Parameters:
a - an Iterator
b - an Iterator
Returns:
a boolean indicating if the two provided Iterators are "equal", using regular Object equality (Equalities.object())

equal

public static <E> boolean equal(Equality<? super E> eq,
                                java.util.Iterator<? extends E> a,
                                java.util.Iterator<? extends E> b)
Returns a boolean indicating if the two provided Iterators are "equal", using the provided Equality. The ordering of the elements is important to this method; i.e., it confirms that the same element occurs in the same position in both iterators.

Parameters:
eq - the Equality to use to test element equality
a - an Iterator
b - an Iterator
Returns:
a boolean indicating if the two provided Iterators are "equal", using regular Object equality (Equalities.object())

contains

public static <E> boolean contains(E find,
                                   java.lang.Iterable<E> iter)
Returns a boolean indicating if the provided Iterable contains an element equal to the provided object, as determined by regular Object equality (Equalities.object()). It achieves this by creating an Iterator from the Iterable and consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
find - value to find
iter - values to look through
Returns:
a boolean indicating if the Iterable contains the provided value

contains

public static <E> boolean contains(E find,
                                   java.util.Iterator<E> iter)
Returns a boolean indicating if the provided Iterator contains an element equal to the provided object, as determined by regular Object equality (Equalities.object()). It achieves this by consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
find - value to find
iter - values to look through
Returns:
a boolean indicating if the Iterator contains the provided value

contains

public static <E> boolean contains(Equality<? super E> eq,
                                   E find,
                                   java.lang.Iterable<E> iter)
Returns a boolean indicating if the provided Iterable contains an element equal to the provided object, as determined by the provided Equality. It achieves this by creating an Iterator from the Iterable and consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
eq - the Equality to use
find - value to find
iter - values to look through
Returns:
a boolean indicating if the Iterable contains the provided value

contains

public static <E> boolean contains(Equality<? super E> eq,
                                   E find,
                                   java.util.Iterator<E> iter)
Returns a boolean indicating if the provided Iterator contains an element equal to the provided object, as determined by the provided Equality. It achieves this by consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
eq - the Equality to use
find - value to find
iter - values to look through
Returns:
a boolean indicating if the Iterator contains the provided value

count

public static <E> int count(E find,
                            java.lang.Iterable<E> iter)
Returns an int representing the number of occurrences, in the provided Iterable, of elements equal to the provided object, as determined by regular Object equality (Equalities.object()). It achieves this by creating an Iterator from the Iterable and consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
find - value to find
iter - values to look through
Returns:
an int representing the number of occurrences in the Iterable of the provided value

count

public static <E> int count(E find,
                            java.util.Iterator<E> iter)
Returns an int representing the number of occurrences, in the provided Iterator, of elements equal to the provided object, as determined by regular Object equality (Equalities.object()). It achieves this by consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
find - value to find
iter - values to look through
Returns:
an int representing the number of occurrences in the Iterable of the provided value

count

public static <E> int count(Equality<? super E> eq,
                            E find,
                            java.lang.Iterable<E> iter)
Returns an int representing the number of occurrences, in the provided Iterable, of elements equal to the provided object, as determined by the provided Equality. It achieves this by creating an Iterator from the Iterable and consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
eq - the Equality to use
find - value to find
iter - values to look through
Returns:
an int representing the number of occurrences in the Iterable of the provided value

count

public static <E> int count(Equality<? super E> eq,
                            E find,
                            java.util.Iterator<E> iter)
Returns an int representing the number of occurrences, in the provided Iterator, of elements equal to the provided object, as determined by the provided Equality. It achieves this by consuming the input until an equal value is found, or the Iterator is exhausted.

Parameters:
eq - the Equality to use
find - value to find
iter - values to look through
Returns:
an int representing the number of occurrences in the Iterable of the provided value

destroyAsConsumed

public static <E> java.util.Iterator<E> destroyAsConsumed(java.util.Iterator<E> iter)
Return an Iterator that wraps the provided Iterator, and automatically calls remove() after every successful call of next()

Parameters:
iter - the Iterator to wrap (and hence, destroy)
Returns:
an Iterator that wraps the provided Iterator, and automatically calls remove() after every successful call of next()

concat

public static <E> ConcatIterable<E> concat(java.lang.Iterable<E> a,
                                           java.lang.Iterable<E> b)
Lazily concatenates the two provided Iterable objects.

Parameters:
a - an Iterable
b - an Iterable
Returns:
the concatenation of b to a (i.e. a followed by b)

concat

public static <E> ConcatIterable<E> concat(java.lang.Iterable<E>... a)
Lazily concatenates the provided Iterable objects.

Parameters:
a - an var-args array of Iterable objects
Returns:
the concatenation of all provided Iterable objects, returned in the order they appear in the array

concat

public static <E> ConcatIterable<E> concat(java.lang.Iterable<? extends java.lang.Iterable<E>> a)
Lazily concatenates the provided Iterable objects.

Parameters:
a - an Iterable of Iterable objects
Returns:
the concatenation of all provided Iterable objects, returned in the order they appear in the Iterable

concat

public static <E> ConcatIterator<E> concat(java.util.Iterator<? extends java.util.Iterator<E>> a)
Lazily concatenates the provided Iterator objects.

Parameters:
a - an Iterator of Iterator objects
Returns:
the concatenation of all provided Iterator objects, returned in the order they appear in the Iterator

onceIterable

public static <E> java.lang.Iterable<E> onceIterable(java.util.Iterator<E> iter)
Create a one-shot Iterable from the supplied Iterator

Parameters:
iter - an Iterator
Returns:
an Iterable which returns the provided Iterator for every call to iterator()

head

public static <E> HeadIterator<E> head(java.util.Iterator<E> iter,
                                       int count)
Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)

Parameters:
iter - an Iterator
count - the number of elements to return from the Iterator
Returns:
an Iterator returning the first count elements of the supplied Iterator

head

public static <E> HeadIterator<E> head(int count,
                                       java.util.Iterator<E> iter)
Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)

Parameters:
count - the number of elements to return from the Iterator
iter - an Iterator
Returns:
an Iterator returning the first count elements of the supplied Iterator

head

public static <E> HeadClosableIterator<E> head(ClosableIterator<E> iter,
                                               int count)
Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)

Parameters:
iter - an Iterator
count - the number of elements to return from the Iterator
Returns:
an Iterator returning the first count elements of the supplied Iterator

head

public static <E> HeadClosableIterator<E> head(int count,
                                               ClosableIterator<E> iter)
Returns a new Iterator that returns the first count elements of the supplied Iterator (or all of them if that is fewer)

Parameters:
count - the number of elements to return from the Iterator
iter - an Iterator
Returns:
an Iterator returning the first count elements of the supplied Iterator

head

public static <E> HeadIterable<E> head(java.lang.Iterable<E> iter,
                                       int count)
Returns a new Iterable that returns the first count elements of the supplied Iterable (or all of them if that is fewer)

Parameters:
iter - an Iterable
count - the number of elements to return from the Iterable
Returns:
an Iterable returning the first count elements of the supplied Iterable

head

public static <E> HeadIterable<E> head(int count,
                                       java.lang.Iterable<E> iter)
Returns a new Iterable that returns the first count elements of the supplied Iterable (or all of them if that is fewer)

Parameters:
count - the number of elements to return from the Iterable
iter - an Iterable
Returns:
an Iterable returning the first count elements of the supplied Iterable

head

public static <E> java.util.List<E> head(java.util.List<E> list,
                                         int count)
Returns a new List that returns the first count elements of the supplied List (or all of them if that is fewer)

Parameters:
list - an Iterable
count - the number of elements to return from the Iterable
Returns:
a List returning the first count elements of the supplied List

drop

public static <E> java.util.Iterator<E> drop(java.util.Iterator<E> iter,
                                             int count)
Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument

Parameters:
iter - an Iterator
count - the number of elements to ignore from the Iterator
Returns:
an Iterator returning all but the first count elements of the supplied Iterator

drop

public static <E> java.util.Iterator<E> drop(int count,
                                             java.util.Iterator<E> iter)
Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument

Parameters:
count - the number of elements to ignore from the Iterator
iter - an Iterator
Returns:
an Iterator returning all but the first count elements of the supplied Iterator

drop

public static <E> ClosableIterator<E> drop(ClosableIterator<E> iter,
                                           int count)
Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument

Parameters:
iter - an Iterator
count - the number of elements to ignore from the Iterator
Returns:
an Iterator returning all but the first count elements of the supplied Iterator

drop

public static <E> ClosableIterator<E> drop(int count,
                                           ClosableIterator<E> iter)
Consumes the first count elements of the supplied Iterator (or all of them if there are fewer), and returns its argument

Parameters:
iter - an Iterator
count - the number of elements to ignore from the Iterator
Returns:
an Iterator returning all but the first count elements of the supplied Iterator

drop

public static <E> DropIterable<E> drop(java.lang.Iterable<E> iter,
                                       int count)
Returns a new Iterable that returns all but the first count elements of the supplied Iterable (or none of them if there are fewer). The removal of these elements is done for each Iterator constructed by the Iterable

Parameters:
iter - an Iterable
count - the number of elements to ignore from the Iterable
Returns:
an Iterable returning all but the first count elements of the supplied Iterable

drop

public static <E> DropIterable<E> drop(int count,
                                       java.lang.Iterable<E> iter)
Returns a new Iterable that returns all but the first count elements of the supplied Iterable (or none of them if there are fewer). The removal of these elements is done for each Iterator constructed by the Iterable

Parameters:
count - the number of elements to ignore from the Iterable
iter - an Iterable
Returns:
an Iterable returning all but the first count elements of the supplied Iterable

drop

public static <E> java.util.List<E> drop(java.util.List<E> list,
                                         int count)
Returns a List that represents all but the first count elements of the supplied List (or none of them if there are fewer).

Parameters:
count - the number of elements to ignore from the List
list - an List
Returns:
an List returning all but the first count elements of the supplied List

tail

public static <E> java.util.List<E> tail(java.util.List<E> list,
                                         int count)
Returns a List that represents the last count elements of the supplied List (or all of them if there are fewer).

Parameters:
count - the number of elements to take from the end of the List
list - an List
Returns:
an List returning all but the first count elements of the supplied List

toArray

public static <T> T[] toArray(java.lang.Iterable<?> iter,
                              T[] a)
Copy the contents of the provided Iterable into the provided array; if the array is not large enough a new one will be initialised and returned. If the array was not large enough the new array will be the exact size of the number of elements copied.

Parameters:
iter - the Iterable to copy records from
a - the array to copy records to
Returns:
the final array

toArray

public static <T> T[] toArray(java.util.Iterator<?> iter,
                              T[] a)
Copy the contents of the provided Iterator into the provided array; if the array is not large enough a new one will be initialised and returned. If the array was not large enough the new array will be the exact size of the number of elements copied. The Iterator will be fully exhausted to construct the array.

Parameters:
iter - the Iterator to copy records from
a - the array to copy records to
Returns:
the final array

toArray

public static <T> T[] toArray(java.lang.Iterable<?> iter,
                              java.lang.Class<T> clazz)
Copy the contents of the provided Iterable into an array of the provided type. The resulting array's size will be the exact number of elements retrieved from the Iterable.

Parameters:
iter - the Iterable to copy records from
clazz - the type of array to copy the records to
Returns:
the final array

toArray

public static <T> T[] toArray(java.util.Iterator<?> iter,
                              java.lang.Class<T> clazz)
Copy the contents of the provided Iterator into an array of the provided type. The resulting array's size will be the exact number of elements retrieved from the Iterator. The Iterator will be fully exhausted to construct the array.

Parameters:
iter - the Iterator to copy records from
clazz - the type of array to copy the records to
Returns:
the final array

toArray

public static java.lang.Object[] toArray(java.lang.Iterable<?> iter)
Create an Object[] from the supplied Iterable

Parameters:
iter - an Iterable
Returns:
an Object[] of the contents of the supplied Iterator

toArray

public static java.lang.Object[] toArray(java.util.Iterator<?> iter)
Create an Object[] from the supplied Iterator. The Iterator is fully exhausted to construct the array.

Parameters:
iter - an Iterator
Returns:
an Object[] of the contents of the supplied Iterator

toList

public static <E> java.util.List<E> toList(java.lang.Iterable<E> iter)
Create an Arraylist from the supplied Iterable

Parameters:
iter - an Iterable
Returns:
an Arraylist of the contents of the supplied Iterable

toList

public static <E> java.util.List<E> toList(java.util.Iterator<E> iter)
Create an Arraylist from the supplied Iterator. The Iterator is fully exhausted to construct the list.

Parameters:
iter - an Iterator
Returns:
an Arraylist of the contents of the supplied Iterator

toList

public static <E> void toList(java.util.Iterator<E> iter,
                              java.util.List<E> list)
Exhaust the provided Iterator, copying its contents into the provided List

Parameters:
iter - source
list - target

toStrings

public static java.util.List<java.lang.String> toStrings(java.util.List<?> list,
                                                         boolean replaceNulls)
Eagerly convert the provided List into a List of type String, by calling the toString() method on each item. If replaceNulls is true then null values will be replaced by the String "null", otherwise they will remain as null.

Parameters:
list - the iterator to convert to strings
replaceNulls - replace null with "null" if true
Returns:
a List of strings constructed from the provided List

toStrings

public static java.lang.Iterable<java.lang.String> toStrings(java.lang.Iterable<?> iter,
                                                             boolean replaceNulls)
Lazily convert the provided Iterable into an Iterable of type String, by calling the toString() method on each item. If replaceNulls is true then null values will be replaced by the String "null", otherwise they will remain as null.

Parameters:
iter - the Iterable to convert to strings
replaceNulls - replace null with "null" if true
Returns:
an Iterable lazily converting the values of the one provided to strings

toStrings

public static java.util.Iterator<java.lang.String> toStrings(java.util.Iterator<?> iter,
                                                             boolean replaceNulls)
Lazily convert the provided Iterator into an Iterator of type String, by calling the toString() method on each item. If replaceNulls is true then null values will be replaced by the String "null", otherwise they will remain as null.

Parameters:
iter - the iterator to convert to strings
replaceNulls - replace null with "null" if true
Returns:
an Iterator lazily converting the values of the one provided to strings

toStrings

public static ClosableIterator<java.lang.String> toStrings(ClosableIterator<?> iter,
                                                           boolean replaceNulls)
Lazily convert the provided Iterator into an Iterator of type String, by calling the toString() method on each item. If replaceNulls is true then null values will be replaced by the String "null", otherwise they will remain as null.

Parameters:
iter - the iterator to convert to strings
replaceNulls - replace null with "null" if true
Returns:
an Iterator lazily converting the values of the one provided to strings

toString

public static java.lang.String toString(java.lang.Iterable<?> iter)
Returns a string representation of the argument of the form produced by java.util collections

Parameters:
iter - an Iterable
Returns:
a string representation of the argument

toString

public static java.lang.String toString(java.util.Iterator<?> iter)
Returns a string representation of the argument of the form produced by java.util collections. The Iterator is fully exhausted in the construction of this string.

Parameters:
iter - an Iterator
Returns:
a string representation of the argument

toString

public static java.lang.String toString(java.lang.Iterable<?> iter,
                                        java.lang.String delimiter)
Concatenates the elements of the provided Iterable using the provided delimiter

Parameters:
iter - an Iterable
delimiter - the delimiter
Returns:
a string representation of the argument

toString

public static java.lang.String toString(java.util.Iterator<?> iter,
                                        java.lang.String delimiter)
Concatenates the elements of the provided Iterator using the provided delimiter. The Iterator is fully exhausted by the construction of this string.

Parameters:
iter - an Iterator
delimiter - the delimiter
Returns:
a string representation of the argument