Class IterableUtil

java.lang.Object
org.assertj.core.util.IterableUtil

public final class IterableUtil extends Object
  • Method Details

    • isNullOrEmpty

      public static boolean isNullOrEmpty(Iterable<?> iterable)
      Indicates whether the given Iterable is null or empty.
      Parameters:
      iterable - the given Iterable to check.
      Returns:
      true if the given Iterable is null or empty, otherwise false.
    • sizeOf

      public static int sizeOf(Iterable<?> iterable)
      Returns the size of the given Iterable.
      Parameters:
      iterable - the Iterable to get size.
      Returns:
      the size of the given Iterable.
      Throws:
      NullPointerException - if given Iterable is null.
    • nonNullElementsIn

      public static <T> List<T> nonNullElementsIn(Iterable<? extends T> i)
      Returns all the non-null elements in the given Iterable.
      Type Parameters:
      T - the type of elements of the Iterable.
      Parameters:
      i - the given Iterable.
      Returns:
      all the non-null elements in the given Iterable. An empty list is returned if the given Iterable is null.
    • toArray

      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));
       }
      Type Parameters:
      T - the type of elements of the Iterable.
      Parameters:
      iterable - an Iterable to translate in an array.
      Returns:
      all the elements from the given Iterable in an array. null if given Iterable is null.
    • toArray

      public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type)
      Create an typed array from an Iterable.
      Type Parameters:
      T - the type of elements of the Iterable.
      Parameters:
      iterable - an Iterable to translate in an array.
      type - the type of the resulting array.
      Returns:
      all the elements from the given Iterable in an array. null if given Iterable is null.
    • 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)