You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ki...@apache.org on 2019/09/26 12:16:36 UTC

[dubbo] branch master updated: refactor some string operations with StringUtils (#5112)

This is an automated email from the ASF dual-hosted git repository.

kimmking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e10149  refactor some string operations with StringUtils (#5112)
4e10149 is described below

commit 4e101490b227052aefaafffbc247d3826297d2b5
Author: dj080808 <da...@gmail.com>
AuthorDate: Thu Sep 26 20:16:29 2019 +0800

    refactor some string operations with StringUtils (#5112)
    
    refactor string empty check statements.
---
 .../src/main/java/org/apache/dubbo/common/URL.java | 48 +++++++---------------
 .../java/org/apache/dubbo/common/URLBuilder.java   |  2 +-
 .../main/java/org/apache/dubbo/common/Version.java |  6 +--
 3 files changed, 18 insertions(+), 38 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 8da1f53..eb0042b 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -453,7 +453,7 @@ class URL implements Serializable {
     }
 
     static String appendDefaultPort(String address, int defaultPort) {
-        if (address != null && address.length() > 0 && defaultPort > 0) {
+        if (StringUtils.isNotEmpty(address) && defaultPort > 0) {
             int i = address.indexOf(':');
             if (i < 0) {
                 return address + ":" + defaultPort;
@@ -508,7 +508,7 @@ class URL implements Serializable {
 
     public List<String> getParameter(String key, List<String> defaultValue) {
         String value = getParameter(key);
-        if (value == null || value.length() == 0) {
+        if (StringUtils.isEmpty(value)) {
             return defaultValue;
         }
         String[] strArray = COMMA_SPLIT_PATTERN.split(value);
@@ -872,7 +872,7 @@ class URL implements Serializable {
             return false;
         }
         String value = getMethodParameter(method, key);
-        return value != null && value.length() > 0;
+        return StringUtils.isNotEmpty(value);
     }
 
     public boolean isLocalHost() {
@@ -1167,7 +1167,7 @@ class URL implements Serializable {
             List<String> includes = (ArrayUtils.isEmpty(parameters) ? null : Arrays.asList(parameters));
             boolean first = true;
             for (Map.Entry<String, String> entry : new TreeMap<>(getParameters()).entrySet()) {
-                if (entry.getKey() != null && entry.getKey().length() > 0
+                if (StringUtils.isNotEmpty(entry.getKey())
                         && (includes == null || includes.contains(entry.getKey()))) {
                     if (first) {
                         if (concat) {
@@ -1197,7 +1197,7 @@ class URL implements Serializable {
         }
         if (appendUser && StringUtils.isNotEmpty(username)) {
             buf.append(username);
-            if (password != null && password.length() > 0) {
+            if (StringUtils.isNotEmpty(password)) {
                 buf.append(":");
                 buf.append(password);
             }
@@ -1209,7 +1209,7 @@ class URL implements Serializable {
         } else {
             host = getHost();
         }
-        if (host != null && host.length() > 0) {
+        if (StringUtils.isNotEmpty(host)) {
             buf.append(host);
             if (port > 0) {
                 buf.append(":");
@@ -1222,7 +1222,7 @@ class URL implements Serializable {
         } else {
             path = getPath();
         }
-        if (path != null && path.length() > 0) {
+        if (StringUtils.isNotEmpty(path)) {
             buf.append("/");
             buf.append(path);
         }
@@ -1295,11 +1295,11 @@ class URL implements Serializable {
 
     public static String buildKey(String path, String group, String version) {
         StringBuilder buf = new StringBuilder();
-        if (group != null && group.length() > 0) {
+        if (StringUtils.isNotEmpty(group)) {
             buf.append(group).append("/");
         }
         buf.append(path);
-        if (version != null && version.length() > 0) {
+        if (StringUtils.isNotEmpty(version)) {
             buf.append(":").append(version);
         }
         return buf.toString();
@@ -1448,11 +1448,7 @@ class URL implements Serializable {
             return false;
         }
         URL other = (URL) obj;
-        if (host == null) {
-            if (other.host != null) {
-                return false;
-            }
-        } else if (!host.equals(other.host)) {
+        if(!StringUtils.isEquals(host, other.host)) {
             return false;
         }
         if (parameters == null) {
@@ -1462,35 +1458,19 @@ class URL implements Serializable {
         } else if (!parameters.equals(other.parameters)) {
             return false;
         }
-        if (password == null) {
-            if (other.password != null) {
-                return false;
-            }
-        } else if (!password.equals(other.password)) {
+        if(!StringUtils.isEquals(password, other.password)) {
             return false;
         }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
+        if(!StringUtils.isEquals(path, other.path)) {
             return false;
         }
         if (port != other.port) {
             return false;
         }
-        if (protocol == null) {
-            if (other.protocol != null) {
-                return false;
-            }
-        } else if (!protocol.equals(other.protocol)) {
+        if(!StringUtils.isEquals(protocol, other.protocol)) {
             return false;
         }
-        if (username == null) {
-            if (other.username != null) {
-                return false;
-            }
-        } else if (!username.equals(other.username)) {
+        if(!StringUtils.isEquals(username, other.username)) {
             return false;
         }
         return true;
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
index 5c926f9..4709bc1 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
@@ -339,7 +339,7 @@ public final class URLBuilder {
 
     public boolean hasParameter(String key) {
         String value = getParameter(key);
-        return value != null && value.length() > 0;
+        return StringUtils.isNotEmpty(value);
     }
 
     public String getParameter(String key) {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
index 8494fed..581869c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
@@ -162,12 +162,12 @@ public final class Version {
             String version = null;
             if (pkg != null) {
                 version = pkg.getImplementationVersion();
-                if (!StringUtils.isEmpty(version)) {
+                if (StringUtils.isNotEmpty(version)) {
                     return version;
                 }
 
                 version = pkg.getSpecificationVersion();
-                if (!StringUtils.isEmpty(version)) {
+                if (StringUtils.isNotEmpty(version)) {
                     return version;
                 }
             }
@@ -260,7 +260,7 @@ public final class Version {
             URL url = urls.nextElement();
             if (url != null) {
                 String file = url.getFile();
-                if (file != null && file.length() > 0) {
+                if (StringUtils.isNotEmpty(file)) {
                     files.add(file);
                 }
             }