net.jqwik.engine.properties.MaxTriesLoop Maven / Gradle / Ivy
package net.jqwik.engine.properties;
import java.util.function.*;
import net.jqwik.api.*;
import net.jqwik.api.Tuple.*;
public class MaxTriesLoop {
public static T loop(
BooleanSupplier loopCondition,
Function> loopAndReturn,
Function tooManyMissesExceptionSupplier,
int maxMisses
) {
long count = 0;
T value = null;
while (loopCondition.getAsBoolean()) {
Tuple2 result = loopAndReturn.apply(value);
value = result.get2();
if (result.get1()) {
break;
}
if (++count > maxMisses) {
throw tooManyMissesExceptionSupplier.apply(maxMisses);
}
}
return value;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy