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

net.jqwik.engine.properties.arbitraries.exhaustive.MappedExhaustiveGenerator Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.arbitraries.exhaustive;

import java.util.*;
import java.util.function.*;

import net.jqwik.api.*;

public class MappedExhaustiveGenerator implements ExhaustiveGenerator {
	private final ExhaustiveGenerator toMap;
	private final Function mapper;

	public MappedExhaustiveGenerator(ExhaustiveGenerator toMap, Function 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());
			}
		};
	}
}