All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.properties.MaxTriesLoop Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
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