@Test void shouldTransformAndThrowNPEOnWhenOnFailureFunctionIsNullIfSuccess() { assertEquals( "ifFailure is null", assertThrows(NullPointerException.class, () -> SUCCESS.transform(null, s -> { throw ASSERTION_ERROR; })).getMessage() ); }
@SuppressWarnings("unchecked") public <U> Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess) { Objects.requireNonNull(ifFailure, "ifFailure is null"); Objects.requireNonNull(ifSuccess, "ifSuccess is null"); try { return isSuccess() ? (Try<U>) ifSuccess.apply(get()) : (Try<U>) ifFailure.apply(getCause()); } catch (Throwable t) { return failure(t); } }
Try implements Iterable<T>, Serializable { @SuppressWarnings("unchecked") public <U> Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess) { Objects.requireNonNull(ifFailure, "ifFailure is null"); Objects.requireNonNull(ifSuccess, "ifSuccess is null"); try { return isSuccess() ? (Try<U>) ifSuccess.apply(get()) : (Try<U>) ifFailure.apply(getCause()); } catch (Throwable t) { return failure(t); } } }
Try implements Iterable<T>, Serializable { @SuppressWarnings("unchecked") public <U> Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess) { Objects.requireNonNull(ifFailure, "ifFailure is null"); Objects.requireNonNull(ifSuccess, "ifSuccess is null"); try { return isSuccess() ? (Try<U>) ifSuccess.apply(get()) : (Try<U>) ifFailure.apply(getCause()); } catch (Throwable t) { return failure(t); } } private  Try(); }
Try implements Iterable<T>, Serializable { @SuppressWarnings("unchecked") public <U> Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess) { Objects.requireNonNull(ifFailure, "ifFailure is null"); Objects.requireNonNull(ifSuccess, "ifSuccess is null"); try { return isSuccess() ? (Try<U>) ifSuccess.apply(get()) : (Try<U>) ifFailure.apply(getCause()); } catch (Throwable t) { return failure(t); } } private  Try(); static Try<T> of(Callable<? extends T> callable); static Try<Void> run(CheckedRunnable runnable); static Try<T> success(T value); static Try<T> failure(Throwable exception); R collect(Collector<? super T, A, R> collector); Try<Throwable> failed(); Try<T> filter(CheckedPredicate<? super T> predicate); @SuppressWarnings("unchecked") Try<U> flatMap(CheckedFunction<? super T, ? extends Try<? extends U>> mapper); U fold(Function<? super Throwable, ? extends U> ifFailure, Function<? super T, ? extends U> ifSuccess); @Deprecated abstract T get(); @Deprecated abstract Throwable getCause(); T getOrElse(T other); T getOrElseGet(Supplier<? extends T> supplier); T getOrElseThrow(Function<? super Throwable, ? extends X> exceptionProvider); abstract boolean isFailure(); abstract boolean isSuccess(); @Override Iterator<T> iterator(); @SuppressWarnings("unchecked") Try<U> map(CheckedFunction<? super T, ? extends U> mapper); Try<T> mapFailure(CheckedFunction<? super Throwable, ? extends Throwable> mapper); Try<T> onFailure(Consumer<? super Throwable> action); Try<T> onSuccess(Consumer<? super T> action); @SuppressWarnings("unchecked") Try<T> orElse(Callable<? extends Try<? extends T>> callable); @SuppressWarnings("unchecked") Try<T> recover(Class<X> exceptionType, CheckedFunction<? super X, ? extends T> recoveryFunction); @SuppressWarnings("unchecked") Try<T> recoverWith(Class<X> exceptionType, CheckedFunction<? super X, ? extends Try<? extends T>> recoveryFunction); Stream<T> stream(); Optional<T> toOptional(); @SuppressWarnings("unchecked") Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess); @Override abstract boolean equals(Object that); @Override abstract int hashCode(); @Override abstract String toString(); }
Try implements Iterable<T>, Serializable { @SuppressWarnings("unchecked") public <U> Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess) { Objects.requireNonNull(ifFailure, "ifFailure is null"); Objects.requireNonNull(ifSuccess, "ifSuccess is null"); try { return isSuccess() ? (Try<U>) ifSuccess.apply(get()) : (Try<U>) ifFailure.apply(getCause()); } catch (Throwable t) { return failure(t); } } private  Try(); static Try<T> of(Callable<? extends T> callable); static Try<Void> run(CheckedRunnable runnable); static Try<T> success(T value); static Try<T> failure(Throwable exception); R collect(Collector<? super T, A, R> collector); Try<Throwable> failed(); Try<T> filter(CheckedPredicate<? super T> predicate); @SuppressWarnings("unchecked") Try<U> flatMap(CheckedFunction<? super T, ? extends Try<? extends U>> mapper); U fold(Function<? super Throwable, ? extends U> ifFailure, Function<? super T, ? extends U> ifSuccess); @Deprecated abstract T get(); @Deprecated abstract Throwable getCause(); T getOrElse(T other); T getOrElseGet(Supplier<? extends T> supplier); T getOrElseThrow(Function<? super Throwable, ? extends X> exceptionProvider); abstract boolean isFailure(); abstract boolean isSuccess(); @Override Iterator<T> iterator(); @SuppressWarnings("unchecked") Try<U> map(CheckedFunction<? super T, ? extends U> mapper); Try<T> mapFailure(CheckedFunction<? super Throwable, ? extends Throwable> mapper); Try<T> onFailure(Consumer<? super Throwable> action); Try<T> onSuccess(Consumer<? super T> action); @SuppressWarnings("unchecked") Try<T> orElse(Callable<? extends Try<? extends T>> callable); @SuppressWarnings("unchecked") Try<T> recover(Class<X> exceptionType, CheckedFunction<? super X, ? extends T> recoveryFunction); @SuppressWarnings("unchecked") Try<T> recoverWith(Class<X> exceptionType, CheckedFunction<? super X, ? extends Try<? extends T>> recoveryFunction); Stream<T> stream(); Optional<T> toOptional(); @SuppressWarnings("unchecked") Try<U> transform(CheckedFunction<? super Throwable, ? extends Try<? extends U>> ifFailure, CheckedFunction<? super T, ? extends Try<? extends U>> ifSuccess); @Override abstract boolean equals(Object that); @Override abstract int hashCode(); @Override abstract String toString();  }