Class IterableLike


  • public class IterableLike
    extends java.lang.Object
    Implements Iterator methods for unidentified arrays and Iterable things that do not have a more specific type than Object. Note that its elements will be returned as Object, primitives included (will be autoboxed).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private IterableLike()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<java.lang.reflect.Type> elementTypeOf​(java.lang.Object iterable)
      Given an iterable-like object, try to determine its static (i.e, without looking at contents) element type.
      static java.util.Optional<java.lang.reflect.Type> elementTypeOf​(java.lang.reflect.Type type)
      Given an iterable-like type, try to determine its static (i.e, without looking at contents) element type.
      private static java.lang.String getTypeWarning​(java.lang.Class<?> type)  
      static boolean isIterable​(java.lang.Object maybeIterable)
      Returns true if the given object is iterable.
      static java.lang.Iterable<java.lang.Object> iterable​(java.lang.Object iterable)
      Given an iterable object (which may be a iterator, iterable, primitive or reference array), return an iterable over its (possibly boxed) elements.
      static java.util.Iterator<java.lang.Object> of​(java.lang.Object iterable)
      Given an iterable object (which may be a iterator, iterable, primitive or reference array), return an iterator over its (possibly boxed) elements.
      static java.util.stream.Stream<java.lang.Object> stream​(java.lang.Object iterable)
      Given an iterable object (which may be a iterator, iterable, primitive or reference array), return a Stream over its (possibly boxed) elements.
      static java.util.List<java.lang.Object> toList​(java.lang.Object iterable)
      Collect an iterable-like into a newly allocated ArrayList.
      • Methods inherited from class java.lang.Object

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

      • IterableLike

        private IterableLike()
    • Method Detail

      • isIterable

        public static boolean isIterable​(java.lang.Object maybeIterable)
        Returns true if the given object is iterable.
        Parameters:
        maybeIterable - the object that might be iterable.
        Returns:
        whether IterableLike can iterate over the given object.
      • of

        public static java.util.Iterator<java.lang.Object> of​(java.lang.Object iterable)
        Given an iterable object (which may be a iterator, iterable, primitive or reference array), return an iterator over its (possibly boxed) elements.
        Parameters:
        iterable - the iterable-like
        Returns:
        an iterator of the given array's elements
      • elementTypeOf

        public static java.util.Optional<java.lang.reflect.Type> elementTypeOf​(java.lang.Object iterable)
        Given an iterable-like object, try to determine its static (i.e, without looking at contents) element type.
      • elementTypeOf

        public static java.util.Optional<java.lang.reflect.Type> elementTypeOf​(java.lang.reflect.Type type)
        Given an iterable-like type, try to determine its static (i.e, without looking at contents) element type.
      • stream

        public static java.util.stream.Stream<java.lang.Object> stream​(java.lang.Object iterable)
        Given an iterable object (which may be a iterator, iterable, primitive or reference array), return a Stream over its (possibly boxed) elements.
        Returns:
        a stream of the given array's elements
      • iterable

        public static java.lang.Iterable<java.lang.Object> iterable​(java.lang.Object iterable)
        Given an iterable object (which may be a iterator, iterable, primitive or reference array), return an iterable over its (possibly boxed) elements.
        Parameters:
        iterable - the iterable-like to create a real Iterable for
        Returns:
        the created Iterable
      • toList

        public static java.util.List<java.lang.Object> toList​(java.lang.Object iterable)
        Collect an iterable-like into a newly allocated ArrayList.
        Parameters:
        iterable - the iterable-like to collect
        Returns:
        a new list with the elements
      • getTypeWarning

        private static java.lang.String getTypeWarning​(java.lang.Class<?> type)