Skip to content
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

Merged
merged 2 commits into from Jul 25, 2017
Merged

Abstract swap conventions #1533

merged 2 commits into from Jul 25, 2017

Conversation

jodastephen
Copy link
Member

All single currency swap conventions are similar, so this creates an abstraction.

Additional Guavate method to simulate Optional.or.

All single currency swap conventions are similar
Add additional Guavate method for Optional.or
@jodastephen jodastephen requested a review from cjkent July 24, 2017 17:20
* 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
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

@jodastephen jodastephen merged commit f2be48d into master Jul 25, 2017
@jodastephen jodastephen deleted the topic/swap-convention branch July 25, 2017 14:42
@jodastephen jodastephen modified the milestone: v1.4 Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants