Top Constructors Methods
org.assertj.core.util

public final Class IterableUtil

extends Object
Class Inheritance
Static Imports
java.util.Collections.emptyList, .Objects.requireNonNull, java.util.stream.Collectors.toList, org.assertj.core.util.Lists.newArrayList

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if the given Iterable is null or empty, otherwise false.
isNullOrEmpty
(Iterable<?>
the given Iterable to check.
iterable
)

Indicates whether the given Iterable is null or empty.

public static <T> Iterable<T>
iterable(T... elements)

public static <T> Iterator<T>
iterator(T... elements)

private static <T> T[]
newArray(Class<T> type, int length)

public static <
the type of elements of the Iterable.
T
>
List<T>

Returns:

all the non-null elements in the given Iterable. An empty list is returned if the given Iterable is null.
nonNullElementsIn
(Iterable<? extends T>
the given Iterable.
i
)

Returns all the non-null elements in the given Iterable.

public static int

Returns:

the size of the given Iterable.
sizeOf
(Iterable<?>
the Iterable to get size.
iterable
)

Returns the size of the given Iterable.

public static <
the type of elements of the Iterable.
T
>
T[]

Returns:

all the elements from the given Iterable in an array. null if given Iterable is null.
toArray
(Iterable<? extends T>
an Iterable to translate in an array.
iterable
)

Create an array from an Iterable.

public static <
the type of elements of the Iterable.
T
>
T[]

Returns:

all the elements from the given Iterable in an array. null if given Iterable is null.
toArray
(Iterable<? extends T>
an Iterable to translate in an array.
iterable
,
Class<T>
the type of the resulting array.
type
)

Create an typed array from an Iterable.

public static <T> Collection<T>
toCollection(Iterable<T> iterable)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IterableUtilback to summary
private IterableUtil()

Method Detail

isNullOrEmptyback to summary
public static boolean isNullOrEmpty(Iterable<?> iterable)

Indicates whether the given Iterable is null or empty.

Parameters
iterable:Iterable<?>

the given Iterable to check.

Returns:boolean

true if the given Iterable is null or empty, otherwise false.

iterableback to summary
public static <T> Iterable<T> iterable(T... elements)
Annotations
@SafeVarargs
iteratorback to summary
public static <T> Iterator<T> iterator(T... elements)
Annotations
@SafeVarargs
newArrayback to summary
private static <T> T[] newArray(Class<T> type, int length)
Annotations
@SuppressWarnings:unchecked
nonNullElementsInback to summary
public static <T> List<T> nonNullElementsIn(Iterable<? extends T> i)

Returns all the non-null elements in the given Iterable.

Parameters
<T>
the type of elements of the Iterable.
i:Iterable<? extends T>

the given Iterable.

Returns:List<T>

all the non-null elements in the given Iterable. An empty list is returned if the given Iterable is null.

sizeOfback to summary
public static int sizeOf(Iterable<?> iterable)

Returns the size of the given Iterable.

Parameters
iterable:Iterable<?>

the Iterable to get size.

Returns:int

the size of the given Iterable.

Exceptions
NullPointerException:
if given Iterable is null.
toArrayback to summary
public static <T> T[] toArray(Iterable<? extends T> iterable)

Create an array from an 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));
}
Parameters
<T>
the type of elements of the Iterable.
iterable:Iterable<? extends T>

an Iterable to translate in an array.

Returns:T[]

all the elements from the given Iterable in an array. null if given Iterable is null.

Annotations
@SuppressWarnings:unchecked
toArrayback to summary
public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type)

Create an typed array from an Iterable.

Parameters
<T>
the type of elements of the Iterable.
iterable:Iterable<? extends T>

an Iterable to translate in an array.

type:Class<T>

the type of the resulting array.

Returns:T[]

all the elements from the given Iterable in an array. null if given Iterable is null.

toCollectionback to summary
public static <T> Collection<T> toCollection(Iterable<T> iterable)