
com.puresoltechnologies.streaming.ConvertingStreamIterator Maven / Gradle / Ivy
package com.puresoltechnologies.streaming;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Function;
/**
* This is a special decorator for {@link Iterator} to convert the iterator
* elements into a new type.
*
* @author Rick-Rainer Ludwig
*
* @param
* is the element type of the base iterator.
* @param
* is the element type of this iterator.
*/
public class ConvertingStreamIterator extends AbstractStreamIterator {
private final Iterator origin;
private final Function converter;
public ConvertingStreamIterator(Iterator origin, Function converter) {
Objects.requireNonNull(origin, "Origin iterator must not be null");
Objects.requireNonNull(converter, "Converter must not be null");
this.origin = origin;
this.converter = converter;
}
@Override
protected F findNext() {
if (origin.hasNext()) {
T next = origin.next();
return converter.apply(next);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy