dubbo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] JackLee1993 closed pull request #1475: update StringUtils isBlank and add isNotBlank method
Date Wed, 21 Mar 2018 11:45:47 GMT
JackLee1993 closed pull request #1475: update StringUtils isBlank and add isNotBlank method
URL: https://github.com/apache/incubator-dubbo/pull/1475
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/beanutil/JavaBeanDescriptor.java
b/dubbo-common/src/main/java/com/alibaba/dubbo/common/beanutil/JavaBeanDescriptor.java
index ab6060663d..456833397c 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/beanutil/JavaBeanDescriptor.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/beanutil/JavaBeanDescriptor.java
@@ -22,6 +22,9 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import static com.alibaba.dubbo.common.utils.Assert.notBlank;
+import static com.alibaba.dubbo.common.utils.Assert.notNull;
+
 public final class JavaBeanDescriptor implements Serializable, Iterable<Map.Entry<Object,
Object>> {
 
     public static final int TYPE_CLASS = 1;
@@ -65,7 +68,7 @@ public JavaBeanDescriptor() {
     }
 
     public JavaBeanDescriptor(String className, int type) {
-        notEmpty(className, "class name is empty");
+        notBlank(className, "class name is empty");
         if (!isValidType(type)) {
             throw new IllegalArgumentException(
                     new StringBuilder(16).append("type [ ")
@@ -195,20 +198,4 @@ public int propertySize() {
     private boolean isValidType(int type) {
         return TYPE_MIN <= type && type <= TYPE_MAX;
     }
-
-    private void notNull(Object obj, String message) {
-        if (obj == null) {
-            throw new IllegalArgumentException(message);
-        }
-    }
-
-    private void notEmpty(String string, String message) {
-        if (isEmpty(string)) {
-            throw new IllegalArgumentException(message);
-        }
-    }
-
-    private boolean isEmpty(String string) {
-        return string == null || "".equals(string.trim());
-    }
 }
diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
index 72a242f9bc..54ec69333c 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
@@ -34,4 +34,15 @@ public static void notNull(Object obj, RuntimeException exeception) {
         }
     }
 
+    public static void notEmpty(String string, String message) {
+        if (StringUtils.isEmpty(string)) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+    public static void notBlank(String string, String message) {
+        if (StringUtils.isBlank(string)) {
+            throw new IllegalArgumentException(message);
+        }
+    }
 }
diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/StringUtils.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/StringUtils.java
index faf349f801..ee56c4b804 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/StringUtils.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/StringUtils.java
@@ -48,9 +48,18 @@ private StringUtils() {
     }
 
     public static boolean isBlank(String str) {
-        if (str == null || str.length() == 0)
-            return true;
-        return false;
+        if (isEmpty(str)) return true;
+
+        for (int i = 0; i < str.length(); i++) {
+            if (!Character.isWhitespace(str.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean isNotBlank(String str) {
+        return !isBlank(str);
     }
 
     /**


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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