[GitHub] [commons-lang] Mikhail2048 commented on a change in pull request #857: Add method defaultIfEmpty with lazy default string computation

2022-02-28 Thread GitBox


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



##
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  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 defaultIfNull(T object, Supplier supplier) {
+return object == null ? supplier.get() : object;

Review comment:
   Yeah we can close this PR, it seems that this functionality is already 
present, thank you!




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




[GitHub] [commons-lang] Mikhail2048 commented on a change in pull request #857: Add method defaultIfEmpty with lazy default string computation

2022-02-27 Thread GitBox


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  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 defaultIfNull(T object, Supplier 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;
 }
 
+/**
+ * Returns either the passed in CharSequence, or if the CharSequence is
+ * whitespace, empty ("") or {@code null}, the value produced by {@code 
supplier}.
+ *
+ * Consider to utilize this method instead of {@link 
#defaultIfBlank(CharSequence, CharSequence)}
+ * in case of lazy computation of default string make sense
+ *
+ * Whitespace is defined by {@link Character#isWhitespace(char)}.
+ *
+ * @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  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 defaultIfEmpty(final T source, 
final Supplier 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




[GitHub] [commons-lang] Mikhail2048 commented on a change in pull request #857: Add method defaultIfEmpty with lazy default string computation

2022-02-26 Thread GitBox


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



##
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  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 defaultIfNull(T object, Supplier supplier) {
+return object == null ? supplier.get() : object;

Review comment:
   I  am sorry, but I have not found any method in `ObjectUtils` with such 
signature.  There is `ObjectUtils.getIfNull(T, T)`  method, but it is not a 
lazy implementation




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