@Test public void shouldRecoverSupplierFromSpecificExceptions() { Supplier<String> supplier = () -> { throw new IllegalArgumentException("BAM!"); }; Supplier<String> supplierWithRecovery = SupplierUtils.recover(supplier, asList(IllegalArgumentException.class, IOException.class), (ex) -> "Bla"); String result = supplierWithRecovery.get(); assertThat(result).isEqualTo("Bla"); }
public static <T> Supplier<T> recover(Supplier<T> supplier, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) { return () -> { T result = supplier.get(); if(resultPredicate.test(result)){ return resultHandler.apply(result); } return result; }; }
SupplierUtils { public static <T> Supplier<T> recover(Supplier<T> supplier, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) { return () -> { T result = supplier.get(); if(resultPredicate.test(result)){ return resultHandler.apply(result); } return result; }; } }
SupplierUtils { public static <T> Supplier<T> recover(Supplier<T> supplier, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) { return () -> { T result = supplier.get(); if(resultPredicate.test(result)){ return resultHandler.apply(result); } return result; }; } private  SupplierUtils(); }
SupplierUtils { public static <T> Supplier<T> recover(Supplier<T> supplier, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) { return () -> { T result = supplier.get(); if(resultPredicate.test(result)){ return resultHandler.apply(result); } return result; }; } private  SupplierUtils(); static Supplier<R> andThen(Supplier<T> supplier, Function<T, R> resultHandler); static Supplier<R> andThen(Supplier<T> supplier,
        BiFunction<T, Throwable, R> handler); static Supplier<T> recover(Supplier<T> supplier,
        Predicate<T> resultPredicate, UnaryOperator<T> resultHandler); static Supplier<T> recover(Supplier<T> supplier,
        Function<Throwable, T> exceptionHandler); static Supplier<T> recover(Supplier<T> supplier,
        List<Class<? extends Throwable>> exceptionTypes,
        Function<Throwable, T> exceptionHandler); static Supplier<T> recover(Supplier<T> supplier,
        Class<X> exceptionType,
        Function<Throwable, T> exceptionHandler); static Supplier<R> andThen(Supplier<T> supplier, Function<T, R> resultHandler,
        Function<Throwable, R> exceptionHandler); }
SupplierUtils { public static <T> Supplier<T> recover(Supplier<T> supplier, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) { return () -> { T result = supplier.get(); if(resultPredicate.test(result)){ return resultHandler.apply(result); } return result; }; } private  SupplierUtils(); static Supplier<R> andThen(Supplier<T> supplier, Function<T, R> resultHandler); static Supplier<R> andThen(Supplier<T> supplier,
        BiFunction<T, Throwable, R> handler); static Supplier<T> recover(Supplier<T> supplier,
        Predicate<T> resultPredicate, UnaryOperator<T> resultHandler); static Supplier<T> recover(Supplier<T> supplier,
        Function<Throwable, T> exceptionHandler); static Supplier<T> recover(Supplier<T> supplier,
        List<Class<? extends Throwable>> exceptionTypes,
        Function<Throwable, T> exceptionHandler); static Supplier<T> recover(Supplier<T> supplier,
        Class<X> exceptionType,
        Function<Throwable, T> exceptionHandler); static Supplier<R> andThen(Supplier<T> supplier, Function<T, R> resultHandler,
        Function<Throwable, R> exceptionHandler);  }