Class MoreIterators


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

      • isEmpty

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

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

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

        @Nonnull
        public static <E> Optional<E> firstElement​(Iterator<E> iterator)
        Returns the first element contained in iterator.
        Parameters:
        iterator - the iterator
        Returns:
        an Optional containing the first element of the iterator, or Optional.empty() if the iterator is empty.