Class IterableUtil


  • public final class IterableUtil
    extends java.lang.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​(java.lang.Iterable<?> iterable)
      Indicates whether the given Iterable is null or empty.
      private static <T> T[] newArray​(java.lang.Class<T> type, int length)  
      static <T> java.util.List<T> nonNullElementsIn​(java.lang.Iterable<? extends T> i)
      Returns all the non-null elements in the given Iterable.
      static int sizeOf​(java.lang.Iterable<?> iterable)
      Returns the size of the given Iterable.
      static <T> T[] toArray​(java.lang.Iterable<? extends T> iterable)
      Create an array from an Iterable.
      static <T> T[] toArray​(java.lang.Iterable<? extends T> iterable, java.lang.Class<T> type)
      Create an typed array from an Iterable.
      private static <T> java.util.Collection<T> toCollection​(java.lang.Iterable<T> iterable)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IterableUtil

        private IterableUtil()
    • Method Detail

      • isNullOrEmpty

        public static boolean isNullOrEmpty​(java.lang.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​(java.lang.Iterable<?> iterable)
        Returns the size of the given Iterable.
        Parameters:
        iterable - the Iterable to get size.
        Returns:
        the size of the given Iterable.
        Throws:
        java.lang.NullPointerException - if given Iterable is null.
      • nonNullElementsIn

        public static <T> java.util.List<T> nonNullElementsIn​(java.lang.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​(java.lang.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 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​(java.lang.Iterable<? extends T> iterable,
                                      java.lang.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

        private static <T> java.util.Collection<T> toCollection​(java.lang.Iterable<T> iterable)
      • newArray

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