Class IterableUtil


  • public final class IterableUtil
    extends Object
    • Constructor Detail

      • IterableUtil

        private IterableUtil()
    • Method Detail

      • 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.
      • 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.
      • newArray

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