| 30 | import java.util.function.Supplier; |
| 31 | |
| 32 | public class J { |
| 33 | private static final int tid = 0; |
| 34 | private static List<Runnable> afterStartup = new ArrayList<>(); |
| 35 | private static List<Runnable> afterStartupAsync = new ArrayList<>(); |
| 36 | private static boolean started = false; |
| 37 | |
| 38 | public static void dofor(int a, Function<Integer, Boolean> c, int ch, Consumer<Integer> d) { |
| 39 | for (int i = a; c.apply(i); i += ch) { |
| 40 | c.apply(i); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public static boolean doif(Supplier<Boolean> c, Runnable g) { |
| 45 | if (c.get()) { |
| 46 | g.run(); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | public static void a(Runnable a) { |
| 54 | MultiBurst.burst.lazy(a); |
| 55 | } |
| 56 | |
| 57 | public static <T> Future<T> a(Callable<T> a) { |
| 58 | return MultiBurst.burst.getService().submit(a); |
| 59 | } |
| 60 | |
| 61 | public static void attemptAsync(NastyRunnable r) { |
| 62 | J.a(() -> J.attempt(r)); |
| 63 | } |
| 64 | |
| 65 | public static <R> R attemptResult(NastyFuture<R> r, R onError) { |
| 66 | try { |
| 67 | return r.run(); |
| 68 | } catch (Throwable e) { |
| 69 | e.printStackTrace(); |
| 70 | } |
| 71 | |
| 72 | return onError; |
| 73 | } |
| 74 | |
| 75 | public static <T, R> R attemptFunction(NastyFunction<T, R> r, T param, R onError) { |
| 76 | try { |
| 77 | return r.run(param); |
| 78 | } catch (Throwable e) { |
| 79 | Adapt.verbose("Failed to run function: " + e.getMessage()); |
| 80 | } |
| 81 | |
| 82 | return onError; |
| 83 | } |
| 84 | |
| 85 | public static boolean sleep(long ms) { |
| 86 | return J.attempt(() -> Thread.sleep(ms)); |
| 87 | } |
| 88 | |
| 89 | public static boolean attempt(NastyRunnable r) { |
nothing calls this directly
no outgoing calls
no test coverage detected