hudi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-hudi] leesf commented on a change in pull request #1338: [HUDI-615]: Add Test cases for StringUtils.
Date Sun, 16 Feb 2020 06:07:53 GMT
leesf 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_r379877879
 
 

 ##########
 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:
   hi smarthi, thanks for opening the PR, I am wondering if we really need these methods?
or will them be used somewhere later?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message