Class Iterators


  • @Immutable
    public class Iterators
    extends Object
    A utility for creating iterators.
    Author:
    Randall Hauch
    • Constructor Detail

      • Iterators

        public Iterators()
    • Method Detail

      • empty

        public static <T> Iterator<T> empty()
      • with

        public static <T> Iterator<T> with​(T value)
      • with

        public static <T> Iterator<T> with​(T value1,
                                           T value2)
      • with

        public static <T> Iterator<T> with​(T value1,
                                           T value2,
                                           T value3)
      • with

        @SafeVarargs
        public static <T> Iterator<T> with​(T value1,
                                           T value2,
                                           T value3,
                                           T... additional)
      • with

        public static <T> Iterator<T> with​(T[] values)
      • around

        public static <T,​U,​V> Iterator<V> around​(Iterator<? extends T> first,
                                                             Iterator<? extends U> second,
                                                             BiFunction<T,​U,​V> combineFirstAndSecond)
      • readOnly

        public static <V,​T> Iterator<T> readOnly​(Iterator<? extends V> iterator,
                                                       Function<V,​T> conversion)
      • readOnlyIterable

        public static <T> Iterable<T> readOnlyIterable​(Iterable<T> iterable)
      • readOnlyIterable

        public static <V,​T> Iterable<T> readOnlyIterable​(Iterable<? extends V> iterable,
                                                               Function<V,​T> conversion)
      • join

        public static <T> Iterator<T> join​(Iterable<T> first,
                                           T last1,
                                           T last2)
      • join

        public static <T> Iterator<T> join​(Iterable<T> first,
                                           T last1,
                                           T last2,
                                           T last3)
      • join

        public static <T> Iterator<T> join​(Iterable<T> first,
                                           T last1,
                                           T last2,
                                           T last3,
                                           T last4)
      • toIterable

        public static <T> Iterable<T> toIterable​(Iterator<T> iterator)
        Get an Iterable from an Iterator.
        Type Parameters:
        T - the iterator type
        Parameters:
        iterator - the source iterator
        Returns:
        the iterable
      • transform

        public static <F,​T> Iterator<T> transform​(Iterator<F> fromIterator,
                                                        Function<? super F,​? extends T> function)
        Transform an iterator from a given type to super types.
        Type Parameters:
        F - the source transform type
        T - the destination transform type
        Parameters:
        fromIterator - the source iterator
        function - the function to be applied when performing element transformation
        Returns:
        the transformed iterator
      • preview

        public static <T> Iterators.PreviewIterator<T> preview​(Iterator<T> iter)
        Get a read-only iterator that can peek at the next value before it is retrieved with Iterator.next().
        Parameters:
        iter - the original iterator
        Returns:
        the peeking iterator; may be null if iter is null