Class Iterators


  • class Iterators
    extends java.lang.Object
    Utility class for constructing iterables
    Since:
    3.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Iterators.Abstract<A>
      A template implementation of the Iterator interface, so clients can more easily implement Iterator for some patterns of iteration.
      private static class  Iterators.EmptyIterator  
      (package private) static interface  Iterators.Peek<A>
      Marker interface for use in constructing iterators
      (package private) static interface  Iterators.Peeking<A>
      Iterator that can examine next without removing it
      private static class  Iterators.PeekingImpl<A>
      Implementation of Iterators.Peeking that avoids peeking unless necessary.
      (package private) static class  Iterators.Unmodifiable<E>
      Iterator where Iterators.Unmodifiable.remove() is unsupported.
    • Constructor Summary

      Constructors 
      Constructor Description
      Iterators()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <A> boolean addAll​(java.util.Collection<A> collectionToModify, java.util.Iterator<? extends A> iterator)
      Adds all the elements of the iterator to the collectionToModify
      static <A> java.util.Iterator<A> emptyIterator()
      Iterator with no values inside
      (package private) static <A> Iterators.Peeking<A> peekingIterator​(java.util.Iterator<? extends A> iterator)
      Wrap an iterator to add support for the peek operation.
      (package private) static <A> java.util.Iterator<A> singletonIterator​(A a)
      Iterator that returns a single element
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Iterators

        Iterators()
    • Method Detail

      • addAll

        static <A> boolean addAll​(java.util.Collection<A> collectionToModify,
                                  java.util.Iterator<? extends A> iterator)
        Adds all the elements of the iterator to the collectionToModify
        Type Parameters:
        A - element type
        Parameters:
        collectionToModify - collection to add element to, must not be null
        iterator - source of elements to add, must not be null
        Returns:
        true if any of the elements from iterator were not also in collectionToModify
        Since:
        3.0
      • peekingIterator

        static <A> Iterators.Peeking<A> peekingIterator​(java.util.Iterator<? extends A> iterator)
        Wrap an iterator to add support for the peek operation. Do not maintain a reference to the iterator passed in as a parameter. Iterators are mutable by nature and this function makes no promises about how or when the input iterator will be mutated.
        Type Parameters:
        A - element type
        Parameters:
        iterator - iterator that may not support peek, must not be null
        Returns:
        an iterator for which peek will return Iterator#next without removing the value from the iterator
        Since:
        3.0
      • singletonIterator

        static <A> java.util.Iterator<A> singletonIterator​(A a)
        Iterator that returns a single element
        Type Parameters:
        A - element type
        Parameters:
        a - element to return
        Returns:
        iterator returning only a
        Since:
        3.0
      • emptyIterator

        public static <A> java.util.Iterator<A> emptyIterator()
        Iterator with no values inside
        Type Parameters:
        A - element type
        Returns:
        empty iterator
        Since:
        3.0