com.softicar.platform.common.container.iterator.MappingIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.iterator;
import java.util.Iterator;
import java.util.function.Function;
/**
* An {@link Iterator} that maps the elements from one type to another.
*
* @author Oliver Richers
*/
public class MappingIterator implements Iterator {
private final Iterator sourceIterator;
private final Function mappingFunction;
public MappingIterator(Iterator sourceIterator, Function mappingFunction) {
this.sourceIterator = sourceIterator;
this.mappingFunction = mappingFunction;
}
@Override
public boolean hasNext() {
return sourceIterator.hasNext();
}
@Override
public T next() {
return mappingFunction.apply(sourceIterator.next());
}
@Override
public void remove() {
sourceIterator.remove();
}
}