-
Notifications
You must be signed in to change notification settings - Fork 38.4k
add ObjectUtils.getNonNull/getIfNull/getIfEmpty
#34587
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
Conversation
6c89864
to
d624371
Compare
ObjectUtils.defaultIfNull
ObjectUtils.defaultIfNull/defaultIfEmpty
ObjectUtils.defaultIfNull/defaultIfEmpty
ObjectUtils.getIfNull/getIfEmpty
Signed-off-by: Vincent Potucek <[email protected]>
d624371
to
11c1c8e
Compare
is this any good? @currenjin @bclozel |
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.
Wow, this is amazing! Thank you for going above and beyond by adding the getIfNull
utility method. This is exactly what we needed for more concise code.
I really appreciate your dedication to improving the codebase and making this PR even better. The method looks well-designed with good documentation and examples.
This demonstrates what makes the Spring community so great - collaborative improvement and attention to detail. I'll definitely use this in my implementation to make the code more elegant.
Thank you again for your exceptional contribution!
Signed-off-by: Vincent Potucek <[email protected]>
ObjectUtils.getIfNull/getIfEmpty
ObjectUtils.getNonNull/getIfNull/getIfEmpty
* @return An Optional containing the first non-null object, or an empty Optional if all objects are null. | ||
*/ | ||
@SafeVarargs | ||
public static <T> Optional<T> getNonNull(@Nullable final T... objects) { |
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 would have the bigger impact imho @currenjin
Signed-off-by: Vincent Potucek <[email protected]>
5a89550
to
3470df0
Compare
Signed-off-by: Vincent Potucek <[email protected]>
3470df0
to
bf49b43
Compare
Thanks for your enthusiasm, but we are limiting the scope of our Ultimately, adding/removing methods in Utils classes is mainly a Framework team call. We know the community is using those anyway, but whenever we get contributions for performance improvements, we always consider the use cases in Spring Framework and ignore others. In that sense, Apache commons and similar libraries are a much better fit. I would suggest focusing on the original PR in this case. |
apply: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/ObjectUtils.html#defaultIfNull(T,T)
to (maybe) use here: #34537 (review)