OptionalUtils { @SuppressWarnings("unchecked") public static <T> Optional<T> or(Optional<T> value, Supplier<Optional<? extends T>> supplier) { return value.isPresent() ? value : (Optional<T>) supplier.get(); } 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);  }
@Test public void orUsesValue() { assertThat(OptionalUtils.or(Optional.of("Kevin"), () -> Optional.of("foo")).get(), equalTo("Kevin")); }
@Test public void orGetSupplierValue() { assertThat(OptionalUtils.or(Optional.empty(), () -> Optional.of("foo")).get(), equalTo("foo")); }