All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.jqwik.engine.properties.arbitraries.combinations.DefaultCombinator2 Maven / Gradle / Ivy
package net.jqwik.engine.properties.arbitraries.combinations;
import java.util.*;
import java.util.function.*;
import org.jspecify.annotations.*;
import net.jqwik.api.*;
public class DefaultCombinator2 implements Combinators.Combinator2 {
protected final Arbitrary a2;
protected final Arbitrary a1;
public DefaultCombinator2(Arbitrary a1, Arbitrary a2) {
this.a1 = a1;
this.a2 = a2;
}
@Override
public Arbitrary as(Combinators.F2 super T1, ? super T2, ? extends R> combinator) {
return new CombineArbitrary<>(combineFunction(combinator), a1, a2);
}
@Override
public Combinators.Combinator2 filter(Combinators.F2 super T1, ? super T2, Boolean> filter) {
return new Filtered<>(a1, a2, filter);
}
@SuppressWarnings("unchecked")
protected Function super List>, ? extends R> combineFunction(Combinators.F2 super T1, ? super T2, ? extends R> combinator2) {
return params -> combinator2.apply((T1) params.get(0), (T2) params.get(1));
}
private static class Filtered extends DefaultCombinator2 {
private final Combinators.F2 super T1, ? super T2, Boolean> filter;
private Filtered(Arbitrary a1, Arbitrary a2, Combinators.F2 super T1, ? super T2, Boolean> filter) {
super(a1, a2);
this.filter = filter;
}
@Override
public Arbitrary as(Combinators.F2 super T1, ? super T2, ? extends R> combinator) {
return new CombineArbitrary<>(Function.identity(), a1, a2)
.filter(combineFunction(filter)::apply)
.map(combineFunction(combinator));
}
@Override
public Combinators.Combinator2 filter(Combinators.F2 super T1, ? super T2, Boolean> filter) {
return new Filtered<>(a1, a2, combineFilters(this.filter, filter));
}
private Combinators.F2 combineFilters(
Combinators.F2 super T1, ? super T2, Boolean> first,
Combinators.F2 super T1, ? super T2, Boolean> second
) {
return (t1, t2) -> first.apply(t1, t2) && second.apply(t1, t2);
}
}
}