smarthi commented on a change in pull request #1338: [HUDI-615]: Add Test cases 
for StringUtils.
URL: https://github.com/apache/incubator-hudi/pull/1338#discussion_r379901360
 
 

 ##########
 File path: 
hudi-common/src/main/java/org/apache/hudi/common/util/StringUtils.java
 ##########
 @@ -67,4 +69,29 @@ public static String toHexString(byte[] bytes) {
   public static boolean isNullOrEmpty(String str) {
     return str == null || str.length() == 0;
   }
+
+
+  /**
+   * Returns the given string if it is non-null; the empty string otherwise.
+   *
+   * @param string the string to test and possibly return
+   * @return {@code string} itself if it is non-null; {@code ""} if it is null
+   */
+  public static String nullToEmpty(@Nullable String string) {
+    return string == null ? "" : string;
+  }
+
+  /**
+   * Returns the given string if it is nonempty; {@code null} otherwise.
+   *
+   * @param string the string to test and possibly return
+   * @return {@code string} itself if it is nonempty; {@code null} if it is 
empty or null
+   */
+  public static @Nullable String emptyToNull(@Nullable String string) {
+    return stringIsNullOrEmpty(string) ? null : string;
+  }
+
+  private static boolean stringIsNullOrEmpty(@Nullable String string) {
+    return string == null || string.isEmpty();
+  }
 
 Review comment:
   yes these can be used as replacement for Guava-Strings in SparkMain.java.
   Also see 
https://github.com/apache/incubator-hudi/pull/1159#discussion_r363821619 for 
the need to write test cases. 
   
   The new methods will potentially be used in the bigger PR# 1159.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to