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 privateIterableUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisNullOrEmpty(Iterable<?> iterable)Indicates whether the givenIterableisnullor 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-nullelements in the givenIterable.static intsizeOf(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 givenIterableisnullor empty.- Parameters:
iterable- the givenIterableto check.- Returns:
trueif the givenIterableisnullor empty, otherwisefalse.
-
sizeOf
public static int sizeOf(Iterable<?> iterable)
Returns the size of the givenIterable.- Parameters:
iterable- theIterableto get size.- Returns:
- the size of the given
Iterable. - Throws:
NullPointerException- if givenIterableis null.
-
nonNullElementsIn
public static <T> List<T> nonNullElementsIn(Iterable<? extends T> i)
Returns all the non-nullelements in the givenIterable.- Type Parameters:
T- the type of elements of theIterable.- Parameters:
i- the givenIterable.- Returns:
- all the non-
nullelements in the givenIterable. An empty list is returned if the givenIterableisnull.
-
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)
-
-