New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract swap conventions #1533
Conversation
All single currency swap conventions are similar Add additional Guavate method for Optional.or
* The Java 8 {@link Optional} class does not have an {@code or} method, | ||
* so this provides an alternative. | ||
* | ||
* @param <T> the type of element in the iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste error
* | ||
* @param <T> the type of element in the iterable | ||
* @param suppliers the suppliers to combine | ||
* @return the list that combines the inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste error
*/ | ||
@SuppressWarnings("unchecked") | ||
@SafeVarargs | ||
public static <T> Optional<T> firstNotEmpty(Supplier<Optional<? extends T>>... suppliers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equivalent Guava method for null is called firstNonNull
(note "non" instead of "not"). Would it be better to be consistent with that?
*/ | ||
@SuppressWarnings("unchecked") | ||
@SafeVarargs | ||
public static <T> Optional<T> firstNotEmpty(Supplier<Optional<? extends T>>... suppliers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is useful for the use cases in this PR, but would it be worth adding an overload with the signature:
Optional<T> firstNotEmpty(Optional<? extends T>... optionals)
That might be more generally useful.
All single currency swap conventions are similar, so this creates an abstraction.
Additional
Guavate
method to simulateOptional.or
.