Class ConvertingIterator<S,​T>

  • All Implemented Interfaces:
    java.util.Iterator<T>

    public abstract class ConvertingIterator<S,​T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    An Iterator that converts an iterator over objects of type S (the source type) to an iterator over objects of type T (the target type).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Iterator<? extends S> sourceIter
      The source type iterator.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ConvertingIterator​(java.util.Iterator<? extends S> iter)
      Creates a new ConvertingIterator that operates on the supplied source type itertor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract T convert​(S sourceObject)
      Converts a source type object to a target type object.
      boolean hasNext()
      Checks whether the source type itertor contains more elements.
      T next()
      Returns the next element from the source type itertor.
      void remove()
      Calls remove() on the underlying itertor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • sourceIter

        private final java.util.Iterator<? extends S> sourceIter
        The source type iterator.
    • Constructor Detail

      • ConvertingIterator

        protected ConvertingIterator​(java.util.Iterator<? extends S> iter)
        Creates a new ConvertingIterator that operates on the supplied source type itertor.
        Parameters:
        iter - The source type itertor for this ConvertingIterator, must not be null.
    • Method Detail

      • convert

        protected abstract T convert​(S sourceObject)
        Converts a source type object to a target type object.
      • hasNext

        public boolean hasNext()
        Checks whether the source type itertor contains more elements.
        Specified by:
        hasNext in interface java.util.Iterator<S>
        Returns:
        true if the source type itertor contains more elements, false otherwise.
      • next

        public T next()
        Returns the next element from the source type itertor.
        Specified by:
        next in interface java.util.Iterator<S>
        Throws:
        java.util.NoSuchElementException - If all elements have been returned.
        java.lang.IllegalStateException - If the itertor has been closed.
      • remove

        public void remove()
        Calls remove() on the underlying itertor.
        Specified by:
        remove in interface java.util.Iterator<S>
        Throws:
        java.lang.UnsupportedOperationException - If the wrapped itertor does not support the remove operation.
        java.lang.IllegalStateException - If the itertor has been closed, or if next() has not yet been called, or remove() has already been called after the last call to next().