net.jqwik.engine.properties.configurators.UniqueElementsConfigurator Maven / Gradle / Ivy
The newest version!
package net.jqwik.engine.properties.configurators;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;
import net.jqwik.api.*;
import net.jqwik.api.arbitraries.*;
import net.jqwik.api.configurators.*;
import net.jqwik.api.constraints.*;
import net.jqwik.api.providers.*;
import net.jqwik.engine.support.*;
import org.jspecify.annotations.*;
@SuppressWarnings("unchecked")
public class UniqueElementsConfigurator implements ArbitraryConfigurator {
@SuppressWarnings({"OverlyComplexMethod", "OverlyLongMethod"})
@Override
public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) {
return targetType.findAnnotation(UniqueElements.class).map(uniqueness -> {
if (arbitrary instanceof SetArbitrary) {
// Handle SetArbitrary explicitly for optimization
return (Arbitrary) configureSetArbitrary((SetArbitrary>) arbitrary, uniqueness);
}
if (arbitrary instanceof StreamableArbitrary) {
return (Arbitrary) configureStreamableArbitrary((StreamableArbitrary, ?>) arbitrary, uniqueness);
}
if (targetType.isAssignableFrom(List.class)) {
Arbitrary> listArbitrary = (Arbitrary>) arbitrary;
return (Arbitrary) listArbitrary.filter(isUnique(uniqueness));
}
if (targetType.isAssignableFrom(Set.class)) {
Arbitrary> setArbitrary = (Arbitrary>) arbitrary;
return (Arbitrary) setArbitrary.filter(isUnique(uniqueness));
}
if (targetType.isArray()) {
Arbitrary