Class AlteringIterator<T,R>

java.lang.Object
com.github.tommyettinger.ds.support.util.AlteringIterator<T,R>
Type Parameters:
T - the type of items this can return, and the type the wrapped Iterator returns
All Implemented Interfaces:
Iterator<R>

public class AlteringIterator<T,R> extends Object implements Iterator<R>
Wraps an Iterator so that it calls a function on each item it would otherwise return, and returns that function's result. That means this is just like EditingIterator, except this may return a different type than what the iterator returns. This has undefined behavior if any items the Iterator could return are modified during iteration.
You can change both the Iterator and editor at once using set(Iterator, ObjToObjFunction), and can also just change the Iterator with set(Iterator).
  • Field Details

    • iterator

      public Iterator<T> iterator
    • editor

      public com.github.tommyettinger.function.ObjToObjFunction<T,R> editor
  • Constructor Details

    • AlteringIterator

      public AlteringIterator()
    • AlteringIterator

      public AlteringIterator(Iterator<T> iterator, com.github.tommyettinger.function.ObjToObjFunction<T,R> editor)
  • Method Details

    • set

      public void set(Iterator<T> iterator, com.github.tommyettinger.function.ObjToObjFunction<T,R> editor)
    • set

      public void set(Iterator<T> iterator)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public R next()
      Specified by:
      next in interface Iterator<T>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>