public class LogicProcessingUtils {
public static <T, P> T tryToGetResult(int maxTryTimes, Predicate<T> successPredicate, Function<P, T> function, P param) { int tryTimes = 0; T t = null; while (tryTimes < maxTryTimes) { t = function.apply(param); if (successPredicate.test(t)) { break; } tryTimes++; } return t; }
public static <T> T tryToGetResult(int maxTryTimes, Predicate<T> successPredicate, Supplier<T> supplier) { int tryTimes = 0; T t = null; while (tryTimes < maxTryTimes) { t = supplier.get(); if (successPredicate.test(t)) { break; } tryTimes++; } return t; } }
|