net.jqwik.engine.properties.arbitraries.exhaustive.MappedExhaustiveGenerator Maven / Gradle / Ivy
The newest version!
package net.jqwik.engine.properties.arbitraries.exhaustive;
import java.util.*;
import java.util.function.*;
import net.jqwik.api.*;
import org.jspecify.annotations.*;
public class MappedExhaustiveGenerator implements ExhaustiveGenerator {
private final ExhaustiveGenerator toMap;
private final Function super T, ? extends U> mapper;
public MappedExhaustiveGenerator(ExhaustiveGenerator toMap, Function super T, ? extends U> mapper) {this.toMap = toMap;
this.mapper = mapper;
}
@Override
public long maxCount() {
return toMap.maxCount();
}
@Override
public Iterator iterator() {
final Iterator mappedIterator = toMap.iterator();
return new Iterator() {
@Override
public boolean hasNext() {
return mappedIterator.hasNext();
}
@Override
public U next() {
return mapper.apply(mappedIterator.next());
}
};
}
}