All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.javagimmicks.collections8.transformer.TransformingIterator Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
package net.sf.javagimmicks.collections8.transformer;

import java.util.Iterator;
import java.util.function.Function;

import net.sf.javagimmicks.transform8.Transforming;

class TransformingIterator implements Iterator, Transforming
{
   protected final Iterator _internalIterator;
   private final Function _transformer;

   TransformingIterator(Iterator iterator, Function transformer)
   {
      _internalIterator = iterator;
      _transformer = transformer;
   }
   
   public Function getTransformerFunction()
   {
      return _transformer;
   }

   public boolean hasNext()
   {
      return _internalIterator.hasNext();
   }

   public T next()
   {
      return transform(_internalIterator.next());
   }

   public void remove()
   {
      _internalIterator.remove();
   }
   
   protected T transform(F element)
   {
       return getTransformerFunction().apply(element);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy