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

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

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

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

import org.jspecify.annotations.*;

import net.jqwik.api.*;

public class DefaultCombinator3
	extends DefaultCombinator2
	implements Combinators.Combinator3 {
	protected final Arbitrary a3;

	public DefaultCombinator3(Arbitrary a1, Arbitrary a2, Arbitrary a3) {
		super(a1, a2);
		this.a3 = a3;
	}

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

	@Override
	public Combinators.Combinator3 filter(Combinators.F3 filter) {
		return new Filtered<>(a1, a2, a3, filter);
	}

	@SuppressWarnings("unchecked")
	protected  Function, R> combineFunction(Combinators.F3 combinator) {
		return params -> combinator.apply((T1) params.get(0), (T2) params.get(1), (T3) params.get(2));
	}

	private static class Filtered extends DefaultCombinator3 {
		private final Combinators.F3 filter;

		private Filtered(Arbitrary a1, Arbitrary a2, Arbitrary a3, Combinators.F3 filter) {
			super(a1, a2, a3);
			this.filter = filter;
		}

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

		@Override
		public Combinators.Combinator3 filter(Combinators.F3 filter) {
			return new Filtered<>(a1, a2, a3, combineFilters(this.filter, filter));
		}

		@SuppressWarnings("unchecked")
		private Combinators.F3 combineFilters(
			Combinators.F3 filter1,
			Combinators.F3 filter2
		) {
			return (t1, t2, t3) -> filter1.apply(t1, t2, t3) && filter2.apply(t1, t2, t3);
		}

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy