public final class IterableUtil
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
private |
IterableUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isNullOrEmpty(java.lang.Iterable<?> iterable)
Indicates whether the given
Iterable is null or empty. |
static <T> java.lang.Iterable<T> |
iterable(T... elements) |
static <T> java.util.Iterator<T> |
iterator(T... elements) |
private static <T> T[] |
newArray(java.lang.Class<T> type,
int length) |
static <T> java.util.List<T> |
nonNullElementsIn(java.lang.Iterable<? extends T> i)
Returns all the non-
null elements in the given Iterable. |
static int |
sizeOf(java.lang.Iterable<?> iterable)
Returns the size of the given
Iterable. |
static <T> T[] |
toArray(java.lang.Iterable<? extends T> iterable)
Create an array from an
Iterable. |
static <T> T[] |
toArray(java.lang.Iterable<? extends T> iterable,
java.lang.Class<T> type)
Create an typed array from an
Iterable. |
static <T> java.util.Collection<T> |
toCollection(java.lang.Iterable<T> iterable) |
public static boolean isNullOrEmpty(java.lang.Iterable<?> iterable)
Iterable is null or empty.iterable - the given Iterable to check.true if the given Iterable is null or empty, otherwise false.public static int sizeOf(java.lang.Iterable<?> iterable)
Iterable.iterable - the Iterable to get size.Iterable.java.lang.NullPointerException - if given Iterable is null.public static <T> java.util.List<T> nonNullElementsIn(java.lang.Iterable<? extends T> i)
null elements in the given Iterable.T - the type of elements of the Iterable.i - the given Iterable.null elements in the given Iterable. An empty list is returned if the given
Iterable is null.public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable)
Iterable.
Note: this method will return Object[]. If you require a typed array please use toArray(Iterable, Class).
It's main usage is to keep the generic type for chaining call like in:
public S containsOnlyElementsOf(Iterable<? extends T> iterable) {
return containsOnly(toArray(iterable));
}T - the type of elements of the Iterable.iterable - an Iterable to translate in an array.Iterable in an array. null if given Iterable is
null.public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable,
java.lang.Class<T> type)
Iterable.T - the type of elements of the Iterable.iterable - an Iterable to translate in an array.type - the type of the resulting array.Iterable in an array. null if given Iterable is
null.public static <T> java.util.Collection<T> toCollection(java.lang.Iterable<T> iterable)
@SafeVarargs public static <T> java.lang.Iterable<T> iterable(T... elements)
@SafeVarargs public static <T> java.util.Iterator<T> iterator(T... elements)
private static <T> T[] newArray(java.lang.Class<T> type,
int length)