"Unknown executor: " + type + " must be one of " + f.keySet()); ExecutorService executor = factory.apply(type, n, () -> factory(name, daemon, priority), options);
"Unknown executor: " + type + " must be one of " + f.keySet()); ExecutorService executor = factory.apply(type, n, () -> factory(name, daemon, priority), options);
/** * Keep track of routes in the order user define them. * * @param method Route method. * @param pattern Route pattern. * @param filter Route filter. * @param creator Route creator. * @return The same route definition. */ private <T extends Route.Definition> T appendDefinition(String method, String pattern, Route.Filter filter, Throwing.Function4<String, String, Route.Filter, Boolean, T> creator) { String pathPattern = prefixPath(pattern).orElse(pattern); T route = creator.apply(method, pathPattern, filter, caseSensitiveRouting); if (prefix != null) { route.prefix = prefix; // reset name will update the name if prefix != null route.name(route.name()); } bag.add(route); return route; }
/** * A function that remember/cache previous executions. * * @return A memo function. */ default Function4<V1, V2, V3, V4, R> memoized() { if (this instanceof Memoized) { return this; } Map<Object, R> cache = new HashMap<>(); return (Function4<V1, V2, V3, V4, R> & Memoized) (v1, v2, v3, v4) -> memo(cache, Arrays.asList(v1, v2, v3, v4), () -> tryApply(v1, v2, v3, v4)); } }
/** * * Apply this function and run the given action in case of exception. * * @param type Exception filter. * @param action Action to run when exception occurs. * @param <X> Exception type. * @return A new function. */ default <X extends Throwable> Function4<V1, V2, V3, V4, R> onFailure(Class<X> type, java.util.function.Consumer<X> action) { return (v1, v2, v3, v4) -> fnOnFailure(() -> tryApply(v1, v2, v3, v4), type, action); }
/** * Apply this function and returns the given default value in case of exception. * * @param defaultValue Exceptional default value. * @return A new function. */ default Function4<V1, V2, V3, V4, R> orElse(Supplier<R> defaultValue) { return (v1, v2, v3, v4) -> fn(() -> tryApply(v1, v2, v3, v4), defaultValue); }
/** * Apply this function and wrap any resulting exception. * * @param wrapper Exception wrapper. * @return A new function. */ default Function4<V1, V2, V3, V4, R> wrap( java.util.function.Function<Throwable, Exception> wrapper) { return (v1, v2, v3, v4) -> fnWrap(() -> tryApply(v1, v2, v3, v4), wrapper); }
/** * Apply this function to the given argument and produces a result. * * @param v1 Input argument. * @param v2 Input argument. * @param v3 Input argument. * @param v4 Input argument. * @return Result. */ default R apply(V1 v1, V2 v2, V3 v3, V4 v4) { return fn(() -> tryApply(v1, v2, v3, v4)); }
public <V> Value<V> apply(Throwing.Function4<R1, R2, R3, R4, V> fn) { return Try.apply(() -> { try (R1 r1 = this.r1.get(); R2 r2 = this.r2.get(); R3 r3 = this.r3.get(); R4 r4 = this.r4.get()) { return fn.apply(r1, r2, r3, r4); } }); }
/** * Apply this function and unwrap any resulting exception. Useful to get clean/shorter stacktrace. * * @param type Exception to unwrap. * @param <X> Exception type. * @return A new function. */ default <X extends Throwable> Function4<V1, V2, V3, V4, R> unwrap(Class<? extends X> type) { return (v1, v2, v3, v4) -> fnUnwrap(() -> tryApply(v1, v2, v3, v4), type); }
/** * Apply this function or recover from it in case of exception. * * @param fn Exception recover. * @return A new function. */ default Function4<V1, V2, V3, V4, R> recover(java.util.function.Function<Throwable, R> fn) { return recover(Throwable.class, fn); }
/** * Apply this function and run the given action in case of exception. * * @param action Action to run when exception occurs. * @return A new function. */ default Function4<V1, V2, V3, V4, R> onFailure(java.util.function.Consumer<Throwable> action) { return onFailure(Throwable.class, action); }
/** * Apply this function or recover from a specific exception in case of exception. * * @param type Exception filter. * @param fn Exception recover. * @param <X> Exception type. * @return A new function. */ default <X extends Throwable> Function4<V1, V2, V3, V4, R> recover(Class<? extends X> type, java.util.function.Function<X, R> fn) { return (v1, v2, v3, v4) -> fnRecover(() -> tryApply(v1, v2, v3, v4), type, fn); }
/** * Apply this function and returns the given default value in case of exception. * * @param defaultValue Exceptional default value. * @return A new function. */ default Function4<V1, V2, V3, V4, R> orElse(R defaultValue) { return orElse(() -> defaultValue); }
/** * Keep track of routes in the order user define them. * * @param method Route method. * @param pattern Route pattern. * @param filter Route filter. * @param creator Route creator. * @return The same route definition. */ private <T extends Route.Definition> T appendDefinition(String method, String pattern, Route.Filter filter, Throwing.Function4<String, String, Route.Filter, Boolean, T> creator) { String pathPattern = prefixPath(pattern).orElse(pattern); T route = creator.apply(method, pathPattern, filter, caseSensitiveRouting); if (prefix != null) { route.prefix = prefix; // reset name will update the name if prefix != null route.name(route.name()); } bag.add(route); return route; }