![JAR search and dependency download from the Maven repository](/logo.png)
org.jhotdraw8.icollection.impl.iteration.MappedIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.jhotdraw8.icollection Show documentation
Show all versions of org.jhotdraw8.icollection Show documentation
JHotDraw8 Immutable Collections
The newest version!
/*
* @(#)MappedIterator.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.icollection.impl.iteration;
import java.util.Iterator;
import java.util.function.Function;
/**
* Maps an {@link Iterator} to a different element type.
*
* The underlying iterator is referenced - not copied.
*
* @param the mapped element type
* @param the original element type
* @author Werner Randelshofer
*/
public class MappedIterator implements Iterator {
private final Iterator i;
private final Function mappingFunction;
public MappedIterator(Iterator i, Function mappingFunction) {
this.i = i;
this.mappingFunction = mappingFunction;
}
@Override
public boolean hasNext() {
return i.hasNext();
}
@Override
public E next() {
return mappingFunction.apply(i.next());
}
@Override
public void remove() {
i.remove();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy