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

org.jhotdraw8.collection.mapped.MappedIterator Maven / Gradle / Ivy

The newest version!
/*
 * @(#)MappedIterator.java
 * Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
 */

package org.jhotdraw8.collection.mapped;


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 - 2024 Weber Informatics LLC | Privacy Policy