Package org.assertj.core.util
Class IterableUtil
- java.lang.Object
-
- org.assertj.core.util.IterableUtil
-
public final class IterableUtil extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description private
IterableUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isNullOrEmpty(Iterable<?> iterable)
Indicates whether the givenIterable
isnull
or empty.static <T> Iterable<T>
iterable(T... elements)
static <T> Iterator<T>
iterator(T... elements)
private static <T> T[]
newArray(Class<T> type, int length)
static <T> List<T>
nonNullElementsIn(Iterable<? extends T> i)
Returns all the non-null
elements in the givenIterable
.static int
sizeOf(Iterable<?> iterable)
Returns the size of the givenIterable
.static <T> T[]
toArray(Iterable<? extends T> iterable)
Create an array from anIterable
.static <T> T[]
toArray(Iterable<? extends T> iterable, Class<T> type)
Create an typed array from anIterable
.static <T> Collection<T>
toCollection(Iterable<T> iterable)
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(Iterable<?> iterable)
Indicates whether the givenIterable
isnull
or empty.- Parameters:
iterable
- the givenIterable
to check.- Returns:
true
if the givenIterable
isnull
or empty, otherwisefalse
.
-
sizeOf
public static int sizeOf(Iterable<?> iterable)
Returns the size of the givenIterable
.- Parameters:
iterable
- theIterable
to get size.- Returns:
- the size of the given
Iterable
. - Throws:
NullPointerException
- if givenIterable
is null.
-
nonNullElementsIn
public static <T> List<T> nonNullElementsIn(Iterable<? extends T> i)
Returns all the non-null
elements in the givenIterable
.- Type Parameters:
T
- the type of elements of theIterable
.- Parameters:
i
- the givenIterable
.- Returns:
- all the non-
null
elements in the givenIterable
. An empty list is returned if the givenIterable
isnull
.
-
toArray
public static <T> T[] toArray(Iterable<? extends T> iterable)
Create an array from anIterable
.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)); }
-
toArray
public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type)
Create an typed array from anIterable
.
-
toCollection
public static <T> Collection<T> toCollection(Iterable<T> iterable)
-
iterable
@SafeVarargs public static <T> Iterable<T> iterable(T... elements)
-
iterator
@SafeVarargs public static <T> Iterator<T> iterator(T... elements)
-
newArray
private static <T> T[] newArray(Class<T> type, int length)
-
-