12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package thyyxxk.webserver.utils;
- import lombok.extern.slf4j.Slf4j;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.function.Supplier;
- @Slf4j
- public class TryUtil {
- @FunctionalInterface
- public interface TryRunnable {
- void apply();
- }
- public TryUtil() {
- }
- private final List<Supplier<Object>> predicates = new LinkedList<>();
- public static TryUtil create() {
- return new TryUtil();
- }
- public TryUtil fun(Supplier<Object> predicate) {
- this.predicates.add(predicate);
- return this;
- }
- public Object execute() {
- for (Supplier<Object> predicate : predicates) {
- try {
- return predicate.get();
- } catch (Exception ignore) {
- }
- }
- return null;
- }
- public static void ignoreErr(TryRunnable runnable) {
- try {
- runnable.apply();
- } catch (Exception ignore) {
- }
- }
- }
|