Class Iterators


  • public final class Iterators
    extends Object
    Historical utility class containing type safe adapters for some of the iterators of commons-collections.
    • Method Detail

      • singleton

        public static <T> Iterator<T> singleton​(T element)
        Returns an iterator containing the single element element of type T.
        Type Parameters:
        T -
        Parameters:
        element -
        Returns:
      • empty

        public static <T> Iterator<T> empty()
        Returns an empty iterator of type T.
        Type Parameters:
        T -
        Returns:
      • iteratorChain

        public static <T> Iterator<T> iteratorChain​(Iterator<? extends T> iterator1,
                                                    Iterator<? extends T> iterator2)
        Returns an iterator for the concatenation of iterator1 and iterator2.
        Type Parameters:
        T -
        Parameters:
        iterator1 -
        iterator2 -
        Returns:
      • iteratorChain

        public static <T> Iterator<T> iteratorChain​(Iterator<? extends T>[] iterators)
        Returns an iterator for the concatenation of all the given iterators.
        Type Parameters:
        T -
        Parameters:
        iterators -
        Returns:
      • iteratorChain

        public static <T> Iterator<T> iteratorChain​(Collection<Iterator<? extends T>> iterators)
        Returns an iterator for the concatenation of all the given iterators.
        Type Parameters:
        T -
        Parameters:
        iterators -
        Returns:
      • arrayIterator

        public static <T> Iterator<T> arrayIterator​(T[] values,
                                                    int from,
                                                    int to)
        Returns an iterator for elements of an array of values.
        Type Parameters:
        T -
        Parameters:
        values - the array to iterate over.
        from - the index to start iterating at.
        to - the index to finish iterating at.
        Returns:
      • filterIterator

        public static <T> Iterator<T> filterIterator​(Iterator<? extends T> iterator,
                                                     Predicate<? super T> predicate)
        Returns an iterator with elements from an original iterator where the given predicate matches removed.
        Type Parameters:
        T -
        Parameters:
        iterator -
        predicate -
        Returns:
      • transformIterator

        public static <S,​R> Iterator<R> transformIterator​(Iterator<S> iterator,
                                                                Transformer<S,​R> transformer)
        Returns an iterator with elements of an original iterator transformed by a transformer.
        Type Parameters:
        R -
        S -
        Parameters:
        iterator -
        transformer -
        Returns: