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

net.jqwik.engine.properties.arbitraries.combinations.DefaultCombinator6 Maven / Gradle / Ivy

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

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

import net.jqwik.api.*;

import org.jspecify.annotations.*;

public class DefaultCombinator6
	extends DefaultCombinator5
	implements Combinators.Combinator6 {

	protected final Arbitrary a6;

	public DefaultCombinator6(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6) {
		super(a1, a2, a3, a4, a5);
		this.a6 = a6;
	}

	@Override
	public  Arbitrary as(Combinators.F6 combinator) {
		return new CombineArbitrary<>(combineFunction(combinator), a1, a2, a3, a4, a5, a6);
	}

	@Override
	public Combinators.Combinator6 filter(Combinators.F6 filter) {
		return new Filtered<>(a1, a2, a3, a4, a5, a6, filter);
	}

	@SuppressWarnings("unchecked")
	protected  Function, R> combineFunction(Combinators.F6 combinator) {
		return params -> combinator.apply(
			(T1) params.get(0), (T2) params.get(1),
			(T3) params.get(2), (T4) params.get(3),
			(T5) params.get(4), (T6) params.get(5)
		);
	}

	private static class Filtered extends DefaultCombinator6 {
		private final Combinators.F6 filter;

		private Filtered(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4,
			Arbitrary a5,
			Arbitrary a6,
			Combinators.F6 filter
		) {
			super(a1, a2, a3, a4, a5, a6);
			this.filter = filter;
		}

		@Override
		public  Arbitrary as(Combinators.F6 combinator) {
			return new CombineArbitrary<>(Function.identity(), a1, a2, a3, a4, a5, a6)
					   .filter(combineFunction(filter)::apply)
					   .map(combineFunction(combinator));
		}

		@Override
		public Combinators.Combinator6 filter(Combinators.F6 filter) {
			return super.filter(combineFilters(this.filter, filter));
		}

		private Combinators.F6 combineFilters(
			Combinators.F6 first,
			Combinators.F6 second
		) {
			return (p1, p2, p3, p4, p5, p6) -> first.apply(p1, p2, p3, p4, p5, p6)
												   && second.apply(p1, p2, p3, p4, p5, p6);
		}

	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy