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

net.jqwik.engine.properties.arbitraries.MappedEdgeCasesConsumer Maven / Gradle / Ivy

The newest version!
package net.jqwik.engine.properties.arbitraries;

import java.util.function.*;

import net.jqwik.api.*;

class MappedEdgeCasesConsumer implements Consumer> {

	private final Consumer> tConfigurator;
	private final Function utMapper;
	private final Function tuMapper;

	MappedEdgeCasesConsumer(
			Consumer> tConfigurator,
			Function utMapper,
			Function tuMapper
	) {
		this.tConfigurator = tConfigurator;
		this.utMapper = utMapper;
		this.tuMapper = tuMapper;
	}

	@Override
	public void accept(EdgeCases.Config uConfig) {

		EdgeCases.Config tConfig = new EdgeCases.Config() {
			@Override
			public EdgeCases.Config none() {
				uConfig.none();
				return this;
			}

			@Override
			public EdgeCases.Config filter(Predicate filter) {
				uConfig.filter(u -> filter.test(utMapper.apply(u)));
				return this;
			}

			@SuppressWarnings("unchecked")
			@SafeVarargs
			@Override
			public final EdgeCases.Config add(T... edgeCases) {
				for (T edgeCase : edgeCases) {
					uConfig.add(tuMapper.apply(edgeCase));
				}
				return this;
			}

			@SuppressWarnings("unchecked")
			@Override
			public EdgeCases.Config includeOnly(T... includedValues) {
				Object[] includedBigIntegers = new Object[includedValues.length];
				for (int i = 0; i < includedValues.length; i++) {
					includedBigIntegers[i] = tuMapper.apply(includedValues[i]);
				}
				uConfig.includeOnly((U[]) includedBigIntegers);
				return this;
			}
		};
		tConfigurator.accept(tConfig);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy