Class MoreIterables


  • @ParametersAreNonnullByDefault
    public final class MoreIterables
    extends Object
    Static utility methods related to Iterable instances.
    • Method Detail

      • stream

        @Nonnull
        public static <E> Stream<E> stream​(@Nullable
                                           Iterable<E> iterable)
        Returns a sequential Stream of the contents of iterable.
        Parameters:
        iterable - the iterable
        Returns:
        a sequential Stream of the contents of iterable
      • parallelStream

        @Nonnull
        public static <E> Stream<E> parallelStream​(@Nullable
                                                   Iterable<E> iterable)
        Returns a parallel Stream of the contents of iterable.
        Parameters:
        iterable - the iterable
        Returns:
        a parallel Stream of the contents of iterable
      • isEmpty

        public static boolean isEmpty​(Iterable<?> iterable)
        Determines if the given iterable contains no element.
        Parameters:
        iterable - the iterable
        Returns:
        true if the iterable contains no element
      • notEmpty

        public static boolean notEmpty​(Iterable<?> iterable)
        Determines if the given iterable contains at least one element.
        Parameters:
        iterable - the iterable
        Returns:
        true if the iterable contains at least one element
      • onlyElement

        @Nonnull
        public static <E> Optional<E> onlyElement​(Iterable<E> iterable)
        Returns the single element contained in iterable.
        Parameters:
        iterable - the iterable
        Returns:
        an Optional containing the single element of the iterable, or Optional.empty() if the iterable is empty.
        Throws:
        IllegalArgumentException - if the iterable contains more than one element
      • firstElement

        @Nonnull
        public static <E> Optional<E> firstElement​(Iterable<E> iterable)
        Returns the first element contained in iterable.
        Parameters:
        iterable - the iterable
        Returns:
        an Optional containing the first element of the iterable, or Optional.empty() if the iterable is empty.
        Throws:
        IllegalArgumentException - if the iterable contains more than one element