Mikhail2048 commented on a change in pull request #857: URL: https://github.com/apache/commons-lang/pull/857#discussion_r815413552
########## File path: src/main/java/org/apache/commons/lang3/ObjectUtils.java ########## @@ -1152,6 +1152,20 @@ public static boolean isNotEmpty(final Object object) { return result; } + /** + * Get passed {@code object} in case it is not null, otherwise return the value produced by supplier + * + * Consider to utilize this method if lazy computation of default value makes sense in your case + * + * @param object to get if not null else to apply passed {@link Supplier} + * @param supplier {@link Supplier} to utilize in case provided {@code object} is null + * @param <T> the type of the object + * @return passed {@code object} in case it is not null, otherwise return the value produced by supplier + */ + public static <T> T defaultIfNull(T object, Supplier<T> supplier) { + return object == null ? supplier.get() : object; Review comment: @garydgregory Yeah, thats true) ########## File path: src/main/java/org/apache/commons/lang3/StringUtils.java ########## @@ -1523,6 +1523,26 @@ public static int countMatches(final CharSequence str, final CharSequence sub) { return isBlank(str) ? defaultStr : str; } + /** + * <p>Returns either the passed in CharSequence, or if the CharSequence is + * whitespace, empty ("") or {@code null}, the value produced by {@code supplier}.</p> + * + * Consider to utilize this method instead of {@link #defaultIfBlank(CharSequence, CharSequence)} + * in case of lazy computation of default string make sense + * + * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> + * + * @param source - CharSequence to check, may be null + * @param supplier represents the supplier, that should return instance + * of type {@literal T} in case source string is empty + * @param <T> represents the specific kind of CharSequence + * @return the passed source instance of CharSequence in case it is not blank, + * otherwise the value returned by {@link Supplier} + */ + public static <T extends CharSequence> T defaultIfEmpty(final T source, final Supplier<T> supplier) { + return isBlank(source) ? supplier.get() : source; Review comment: @garydgregory correct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org