Class TransformedIterator<E,T>

java.lang.Object
org.apache.commons.functor.core.collection.TransformedIterator<E,T>
Type Parameters:
E - the function argument type
T - the iterator elements type
All Implemented Interfaces:
Iterator<T>

public final class TransformedIterator<E,T> extends Object implements Iterator<T>
Iterator that transforms another Iterator by applying a UnaryFunction to each returned element.
Version:
$Revision$ $Date$
  • Field Details

    • function

      private final UnaryFunction<? super E, ? extends T> function
      The function to apply to each iterator element.
    • iterator

      private final Iterator<? extends E> iterator
      The wrapped iterator.
  • Constructor Details

    • TransformedIterator

      public TransformedIterator(Iterator<? extends E> iterator, UnaryFunction<? super E, ? extends T> function)
      Create a new TransformedIterator.
      Parameters:
      iterator - Iterator to decorate
      function - to apply
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<E>
      See Also:
    • next

      public T next()
      Specified by:
      next in interface Iterator<E>
      See Also:
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<E>
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • transform

      public static <E,T> Iterator<T> transform(Iterator<? extends E> iter, UnaryFunction<? super E, ? extends T> func)
      Get a Transformed Iterator instance.
      Type Parameters:
      E - the function argument type
      T - the iterator elements type
      Parameters:
      iter - to decorate, if null result is null
      func - transforming function, cannot be null
      Returns:
      Iterator
    • maybeTransform

      public static <E> Iterator<?> maybeTransform(Iterator<? extends E> iter, UnaryFunction<? super E, ?> func)
      Get an Iterator instance that may be transformed.
      Type Parameters:
      E - the iterator elements type
      Parameters:
      iter - to decorate, if null result is null
      func - transforming function, if null result is iter
      Returns:
      Iteratorinvalid input: '<'?>