garydgregory commented on a change in pull request #857:
URL: https://github.com/apache/commons-lang/pull/857#discussion_r813763342



##########
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:
       This duplicates:
   - `StringUtils.getIfBlank(T, Supplier<T>)`
   - `StringUtils.getIfEmpty(T, Supplier<T>)`




-- 
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


Reply via email to