net.jqwik.engine.properties.configurators.UniqueElementsConfigurator Maven / Gradle / Ivy
package net.jqwik.engine.properties.configurators;
import java.util.*;
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.*;
@SuppressWarnings("unchecked")
public class UniqueElementsConfigurator implements ArbitraryConfigurator {
@SuppressWarnings("OverlyComplexMethod")
@Override
public Arbitrary configure(Arbitrary arbitrary, TypeUsage targetType) {
return targetType.findAnnotation(UniqueElements.class).map(uniqueness -> {
if (arbitrary instanceof ListArbitrary) {
return (Arbitrary) configureListArbitrary((ListArbitrary>) arbitrary, uniqueness);
}
if (arbitrary instanceof SetArbitrary) {
return (Arbitrary) configureSetArbitrary((SetArbitrary>) arbitrary, uniqueness);
}
if (arbitrary instanceof ArrayArbitrary) {
return (Arbitrary) configureArrayArbitrary((ArrayArbitrary, ?>) arbitrary, uniqueness);
}
if (arbitrary instanceof StreamArbitrary) {
return (Arbitrary) configureStreamArbitrary((StreamArbitrary>) arbitrary, uniqueness);
}
if (arbitrary instanceof IteratorArbitrary) {
return (Arbitrary) configureIteratorArbitrary((IteratorArbitrary>) arbitrary, uniqueness);
}
if (targetType.isAssignableFrom(List.class)) {
Arbitrary> listArbitrary = (Arbitrary>) arbitrary;
return (Arbitrary) listArbitrary.filter(l -> isUnique(l, (Function
© 2015 - 2024 Weber Informatics LLC | Privacy Policy