com.github.azbh111.utils.java.iterable.model.IteratorMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils-java Show documentation
Show all versions of utils-java Show documentation
com.github.azbh111:utils-java
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());
}
}