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

net.jqwik.api.Combinators Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.api;

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

import org.apiguardian.api.*;
import org.jspecify.annotations.*;

import static org.apiguardian.api.API.Status.*;

@API(status = MAINTAINED, since = "1.0")
public class Combinators {

	@API(status = INTERNAL)
	public static abstract class CombinatorsFacade {
		private static final CombinatorsFacade implementation;

		static {
			implementation = FacadeLoader.load(CombinatorsFacade.class);
		}

		public abstract  Combinator2 combine2(Arbitrary a1, Arbitrary a2);

		public abstract  Combinator3 combine3(Arbitrary a1, Arbitrary a2, Arbitrary a3);

		public abstract  Combinator4 combine4(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4
		);

		public abstract  Combinator5 combine5(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4,
			Arbitrary a5
		);

		public abstract  Combinator6 combine6(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4,
			Arbitrary a5,
			Arbitrary a6
		);

		public abstract  Combinator7 combine7(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4,
			Arbitrary a5,
			Arbitrary a6,
			Arbitrary a7
		);

		public abstract  Combinator8 combine8(
			Arbitrary a1,
			Arbitrary a2,
			Arbitrary a3,
			Arbitrary a4,
			Arbitrary a5,
			Arbitrary a6,
			Arbitrary a7,
			Arbitrary a8
		);

		public abstract  ListCombinator combineList(List> listOfArbitraries);
	}

	private Combinators() {
	}

	/**
	 * Combine 2 arbitraries into one.
	 *
	 * @return Combinator2 instance which can be evaluated using {@linkplain Combinator2#as}
	 */
	public static  Combinator2 combine(Arbitrary a1, Arbitrary a2) {
		return CombinatorsFacade.implementation.combine2(a1, a2);
	}

	/**
	 * Combine 3 arbitraries into one.
	 *
	 * @return Combinator3 instance which can be evaluated using {@linkplain Combinator3#as}
	 */
	public static  Combinator3 combine(Arbitrary a1, Arbitrary a2, Arbitrary a3) {
		return CombinatorsFacade.implementation.combine3(a1, a2, a3);
	}

	/**
	 * Combine 4 arbitraries into one.
	 *
	 * @return Combinator4 instance which can be evaluated using {@linkplain Combinator4#as}
	 */
	public static  Combinator4 combine(
		Arbitrary a1, Arbitrary a2, Arbitrary a3,
		Arbitrary a4
	) {
		return CombinatorsFacade.implementation.combine4(a1, a2, a3, a4);
	}

	/**
	 * Combine 5 arbitraries into one.
	 *
	 * @return Combinator5 instance which can be evaluated using {@linkplain Combinator5#as}
	 */
	public static  Combinator5 combine(
		Arbitrary a1, Arbitrary a2, Arbitrary a3,
		Arbitrary a4, Arbitrary a5
	) {
		return CombinatorsFacade.implementation.combine5(a1, a2, a3, a4, a5);
	}

	/**
	 * Combine 6 arbitraries into one.
	 *
	 * @return Combinator6 instance which can be evaluated using {@linkplain Combinator6#as}
	 */
	public static  Combinator6 combine(
		Arbitrary a1, Arbitrary a2, Arbitrary a3,
		Arbitrary a4, Arbitrary a5, Arbitrary a6
	) {
		return CombinatorsFacade.implementation.combine6(a1, a2, a3, a4, a5, a6);
	}

	/**
	 * Combine 7 arbitraries into one.
	 *
	 * @return Combinator7 instance which can be evaluated using {@linkplain Combinator7#as}
	 */
	public static  Combinator7 combine(
		Arbitrary a1, Arbitrary a2,
		Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7
	) {
		return CombinatorsFacade.implementation.combine7(a1, a2, a3, a4, a5, a6, a7);
	}

	/**
	 * Combine 8 arbitraries into one.
	 *
	 * @return Combinator8 instance which can be evaluated using {@linkplain Combinator8#as}
	 */
	public static  Combinator8 combine(
		Arbitrary a1, Arbitrary a2,
		Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8
	) {
		return CombinatorsFacade.implementation.combine8(a1, a2, a3, a4, a5, a6, a7, a8);
	}

	/**
	 * Combine a list of arbitraries into one.
	 *
	 * @return ListCombinator instance which can be evaluated using {@linkplain ListCombinator#as}
	 */
	public static  ListCombinator combine(List> listOfArbitraries) {
		return CombinatorsFacade.implementation.combineList(listOfArbitraries);
	}

	/**
	 * Combinator for two values.
	 */
	public interface Combinator2 {

		/**
		 * Combine two values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F2 combinator);

		/**
		 * Filter two values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator2 filter(F2 filter);

		/**
		 * Combine two values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F2> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}
	}

	/**
	 * Combinator for three values.
	 */
	public interface Combinator3 {

		/**
		 * Combine three values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F3 combinator);

		/**
		 * Filter three values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator3 filter(F3 filter);

		/**
		 * Combine three values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F3> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}

	}

	/**
	 * Combinator for four values.
	 */
	public interface Combinator4 {

		/**
		 * Combine four values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F4 combinator);

		/**
		 * Filter four values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator4 filter(F4 filter);

		/**
		 * Combine four values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F4> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}

	}

	/**
	 * Combinator for five values.
	 */
	public interface Combinator5 {

		/**
		 * Combine five values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F5 combinator);

		/**
		 * Filter five values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator5 filter(F5 filter);

		/**
		 * Combine five values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F5> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}
	}

	/**
	 * Combinator for six values.
	 */
	public interface Combinator6 {

		/**
		 * Combine six values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F6 combinator);

		/**
		 * Filter six values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator6 filter(F6 filter);

		/**
		 * Combine six values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F6> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}

	}

	/**
	 * Combinator for seven values.
	 */
	public interface Combinator7 {

		/**
		 * Combine seven values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F7 combinator);

		/**
		 * Filter seven values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator7 filter(F7 filter);

		/**
		 * Combine seven values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F7> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}

	}

	/**
	 * Combinator for eight values.
	 */
	public interface Combinator8 {

		/**
		 * Combine eight values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(F8 combinator);

		/**
		 * Filter eight values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		Combinator8 filter(F8 filter);

		/**
		 * Combine eight values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(F8> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}
	}

	/**
	 * Combinator for any number of values.
	 */
	public interface ListCombinator {

		/**
		 * Combine any number of values.
		 *
		 * @param combinator function
		 * @param         return type
		 * @return arbitrary instance
		 */
		 Arbitrary as(Function, ? extends R> combinator);

		/**
		 * Filter list of values to only let them pass if the predicate is true.
		 *
		 * @param filter function
		 * @return combinator instance
		 */
		@API(status = MAINTAINED, since = "1.8.0")
		ListCombinator filter(Predicate> filter);

		/**
		 * Combine list of values to create a new arbitrary.
		 *
		 * @param flatCombinator function
		 * @param             return type of arbitrary
		 * @return arbitrary instance
		 */
		default  Arbitrary flatAs(Function, ? extends Arbitrary> flatCombinator) {
			return as(flatCombinator).flatMap(Function.identity());
		}
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F2 {
		R apply(T1 t1, T2 t2);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F3 {
		R apply(T1 t1, T2 t2, T3 t3);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F4 {
		R apply(T1 t1, T2 t2, T3 t3, T4 t4);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F5 {
		R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F6 {
		R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F7 {
		R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);
	}

	@FunctionalInterface
	@API(status = INTERNAL)
	public interface F8 {
		R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy