1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public class Try { public Try() { }
public static <T, R> Function<T, R> of(Try.UncheckedFunction<T, R> mapper) { Objects.requireNonNull(mapper); return (t) -> { try { return mapper.apply(t); } catch (Exception var3) { throw Exceptions.unchecked(var3); } }; }
public static <T> Consumer<T> of(Try.UncheckedConsumer<T> mapper) { Objects.requireNonNull(mapper); return (t) -> { try { mapper.accept(t); } catch (Exception var3) { throw Exceptions.unchecked(var3); } }; }
public static <T> Supplier<T> of(Try.UncheckedSupplier<T> mapper) { Objects.requireNonNull(mapper); return () -> { try { return mapper.get(); } catch (Exception var2) { throw Exceptions.unchecked(var2); } }; }
@FunctionalInterface public interface UncheckedSupplier<T> { @Nullable T get() throws Exception; }
@FunctionalInterface public interface UncheckedConsumer<T> { @Nullable void accept(@Nullable T t) throws Exception; }
@FunctionalInterface public interface UncheckedFunction<T, R> { @Nullable R apply(@Nullable T t) throws Exception; } }
|