net.jqwik.engine.properties.UniquenessChecker Maven / Gradle / Ivy
package net.jqwik.engine.properties;
import java.util.*;
import java.util.stream.*;
import net.jqwik.api.*;
import org.jspecify.annotations.*;
public class UniquenessChecker {
public static boolean checkShrinkableUniqueIn(Collection extends FeatureExtractor> extractors, Shrinkable shrinkable, List extends Shrinkable> shrinkables) {
if (extractors.isEmpty()) {
return true;
}
T value = shrinkable.value();
List elements = shrinkables.stream().map(Shrinkable::value).collect(Collectors.toList());
return checkValueUniqueIn(extractors, value, elements);
}
public static boolean checkValueUniqueIn(Collection extends FeatureExtractor> extractors, T value, Collection extends T> elements) {
for (FeatureExtractor extractor : extractors) {
if (!extractor.isUniqueIn(value, elements)) {
return false;
}
}
return true;
}
public static boolean checkUniquenessOfShrinkables(Collection extends FeatureExtractor> extractors, List extends Shrinkable> shrinkables) {
if (extractors.isEmpty()) {
return true;
}
List elements = shrinkables.stream().map(Shrinkable::value).collect(Collectors.toList());
return checkUniquenessOfValues(extractors, elements);
}
public static boolean checkUniquenessOfValues(Collection extends FeatureExtractor> extractors, Collection extends T> elements) {
for (FeatureExtractor extractor : extractors) {
if (!extractor.areUnique(elements)) {
return false;
}
}
return true;
}
}