Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Last active May 10, 2024 21:24
Show Gist options
  • Save bogovicj/2c7f350eeb08ad9f55da31ac12afcb2c to your computer and use it in GitHub Desktop.
Save bogovicj/2c7f350eeb08ad9f55da31ac12afcb2c to your computer and use it in GitHub Desktop.
Use the map method to cause a side-effect if the optional is not-empty.
public T getValidateDefault(String parameter, Predicate<T> validator, T defaultValue) {
return getOptional(parameter).filter(validator)
.map(x -> {
allDefault = false;
return x;
}).orElse(defaultValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment