@Test public void invokesEmptyAction() { OptionalUtils.ifPresentOrElse(Optional.empty(), (i) -> new RuntimeException("Failure"), () -> {}); }
public static <T> void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) { if (value.isPresent()) { action.accept(value.get()); } else { emptyAction.run(); } }
OptionalUtils { public static <T> void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) { if (value.isPresent()) { action.accept(value.get()); } else { emptyAction.run(); } } }
OptionalUtils { public static <T> void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) { if (value.isPresent()) { action.accept(value.get()); } else { emptyAction.run(); } } private  OptionalUtils(); }
OptionalUtils { public static <T> void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) { if (value.isPresent()) { action.accept(value.get()); } else { emptyAction.run(); } } private  OptionalUtils(); @SuppressWarnings("unchecked") static Optional<T> or(Optional<T> value, Supplier<Optional<? extends T>> supplier); static Stream<T> stream(Optional<T> value); static void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction); }
OptionalUtils { public static <T> void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) { if (value.isPresent()) { action.accept(value.get()); } else { emptyAction.run(); } } private  OptionalUtils(); @SuppressWarnings("unchecked") static Optional<T> or(Optional<T> value, Supplier<Optional<? extends T>> supplier); static Stream<T> stream(Optional<T> value); static void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction);  }