com.exasol.adapter.document.iterators.TransformingIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtual-schema-common-document Show documentation
Show all versions of virtual-schema-common-document Show documentation
Common module of Exasol Virtual Schema Adapters for Document Data Sources.
The newest version!
package com.exasol.adapter.document.iterators;
import java.util.Iterator;
import java.util.function.Function;
/**
* This class applies a transformation function on an {@link Iterator}.
*
* @param input type
* @param output type
*/
public class TransformingIterator implements CloseableIterator {
private final CloseableIterator source;
private final Function mapFunction;
/**
* Create a new instance of {@link TransformingIterator}.
*
* @param source source iterator
* @param mapFunction transformation function
*/
public TransformingIterator(final CloseableIterator source, final Function mapFunction) {
this.source = source;
this.mapFunction = mapFunction;
}
@Override
public boolean hasNext() {
return this.source.hasNext();
}
@Override
public R next() {
return this.mapFunction.apply(this.source.next());
}
@Override
public void close() {
this.source.close();
}
}