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

com.exasol.adapter.document.iterators.TransformingIterator Maven / Gradle / Ivy

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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy