@Test public void orElseGet() { assertEquals((Integer) 1, ValueWrapper.of(1).orElseGet(() -> 3)); assertEquals(3, ValueWrapper.errorWithValidValue(null, null).orElseGet(() -> 3)); assertNull(ValueWrapper.of(null).orElseGet(() -> 3)); }
public T orElseGet(Supplier<T> defaultSupplier) { return valid ? value : defaultSupplier.get(); }
ValueWrapper { public T orElseGet(Supplier<T> defaultSupplier) { return valid ? value : defaultSupplier.get(); } }
ValueWrapper { public T orElseGet(Supplier<T> defaultSupplier) { return valid ? value : defaultSupplier.get(); } private  ValueWrapper(T value, T expected, boolean valid, String errorMessage); }
ValueWrapper { public T orElseGet(Supplier<T> defaultSupplier) { return valid ? value : defaultSupplier.get(); } private  ValueWrapper(T value, T expected, boolean valid, String errorMessage); static ValueWrapper<T> of(T value); static ValueWrapper<T> errorWithValidValue(T value, T expected); static ValueWrapper<T> errorWithMessage(String message); static ValueWrapper<T> errorEmptyMessage(); boolean isValid(); T getValue(); T getExpected(); Optional<String> getErrorMessage(); T orElse(T defaultValue); T orElseGet(Supplier<T> defaultSupplier); }
ValueWrapper { public T orElseGet(Supplier<T> defaultSupplier) { return valid ? value : defaultSupplier.get(); } private  ValueWrapper(T value, T expected, boolean valid, String errorMessage); static ValueWrapper<T> of(T value); static ValueWrapper<T> errorWithValidValue(T value, T expected); static ValueWrapper<T> errorWithMessage(String message); static ValueWrapper<T> errorEmptyMessage(); boolean isValid(); T getValue(); T getExpected(); Optional<String> getErrorMessage(); T orElse(T defaultValue); T orElseGet(Supplier<T> defaultSupplier);  }