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

com.softicar.platform.common.container.iterator.MappingIterator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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();
	}
}