Class Iterators


  • public final class Iterators
    extends java.lang.Object
    Utility class containing type safe adapters for some of the iterators of commons-collections.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Iterator<T> arrayIterator​(T[] values, int from, int to)
      Returns an iterator for elements of an array of values.
      static <T> java.util.Iterator<T> empty()
      Returns an empty iterator of type T.
      static <T> java.util.Iterator<T> filterIterator​(java.util.Iterator<? extends T> iterator, Predicate<? super T> predicate)
      Returns an iterator with elements from an original iterator where the given predicate matches removed.
      static <T> java.util.Iterator<T> iteratorChain​(java.util.Collection<? extends T> iterators)
      Returns an iterator for the concatenation of all the given iterators.
      static <T> java.util.Iterator<T> iteratorChain​(java.util.Iterator<? extends T>[] iterators)
      Returns an iterator for the concatenation of all the given iterators.
      static <T> java.util.Iterator<T> iteratorChain​(java.util.Iterator<? extends T> iterator1, java.util.Iterator<? extends T> iterator2)
      Returns an iterator for the concatenation of iterator1 and iterator2.
      static java.util.Iterator<Node> nodes​(NodeIterator nodeIterator)
      Returns an iterator of Node from a NodeIterator.
      static java.util.Iterator<Property> properties​(PropertyIterator propertyIterator)
      Returns an iterator of Property from a PropertyIterator.
      static <T> java.util.Iterator<T> singleton​(T element)
      Returns an iterator containing the single element element of type T.
      static <T,​R,​S extends T>
      java.util.Iterator<R>
      transformIterator​(java.util.Iterator<? extends T> iterator, Transformer<S,​? super R> transformer)
      Returns an iterator with elements of an original iterator transformed by a transformer.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • singleton

        public static <T> java.util.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> java.util.Iterator<T> empty()
        Returns an empty iterator of type T.
        Type Parameters:
        T -
        Returns:
      • iteratorChain

        public static <T> java.util.Iterator<T> iteratorChain​(java.util.Iterator<? extends T> iterator1,
                                                              java.util.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> java.util.Iterator<T> iteratorChain​(java.util.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> java.util.Iterator<T> iteratorChain​(java.util.Collection<? extends T> iterators)
        Returns an iterator for the concatenation of all the given iterators.
        Type Parameters:
        T -
        Parameters:
        iterators -
        Returns:
      • arrayIterator

        public static <T> java.util.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> java.util.Iterator<T> filterIterator​(java.util.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 <T,​R,​S extends T> java.util.Iterator<R> transformIterator​(java.util.Iterator<? extends T> iterator,
                                                                                            Transformer<S,​? super R> transformer)
        Returns an iterator with elements of an original iterator transformed by a transformer.
        Type Parameters:
        T -
        R -
        S -
        Parameters:
        iterator -
        transformer -
        Returns:
      • nodes

        public static java.util.Iterator<Node> nodes​(NodeIterator nodeIterator)
        Returns an iterator of Node from a NodeIterator.
        Parameters:
        nodeIterator -
        Returns: