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

com.github.azbh111.utils.java.iterable.model.IteratorMapper Maven / Gradle / Ivy

The newest version!
package com.github.azbh111.utils.java.iterable.model;

import java.util.Iterator;
import java.util.function.Function;

/**
 * @author: zyp
 * @since: 2021/7/27 17:51
 */
public class IteratorMapper implements Iterator {
    private final Iterator source;
    private Function mapper;

    public IteratorMapper(Iterator source, Function mapper) {
        if (source == null) {
            this.source = new EmptyIterator<>();
        } else {
            this.source = source;
        }
        this.mapper = mapper;
    }

    @Override
    public boolean hasNext() {
        return source.hasNext();
    }

    @Override
    public T next() {
        return mapper.apply(source.next());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy