call the util method (#3230)

* Code optimization, call the util method

* mofidy

* modify *

* import package
This commit is contained in:
huazhongming 2019-01-16 15:11:12 +08:00 committed by Ian Luo
parent 416c57529f
commit 458a4504dc
72 changed files with 306 additions and 233 deletions

View File

@ -130,7 +130,7 @@ public class ConfigParser {
sb.append(item.getSide());
}
Map<String, String> parameters = item.getParameters();
if (parameters == null || parameters.isEmpty()) {
if (CollectionUtils.isEmptyMap(parameters)) {
throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " +
"you want to change in the rule.");
}

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.cluster.directory;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
@ -48,8 +49,8 @@ public class StaticDirectory<T> extends AbstractDirectory<T> {
}
public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) {
super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain);
if (invokers == null || invokers.isEmpty()) {
super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain);
if (CollectionUtils.isEmpty(invokers)) {
throw new IllegalArgumentException("invokers == null");
}
this.invokers = invokers;

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster.loadbalance;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.LoadBalance;
@ -44,7 +45,7 @@ public abstract class AbstractLoadBalance implements LoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
if (invokers == null || invokers.isEmpty()) {
if (CollectionUtils.isEmpty(invokers)) {
return null;
}
if (invokers.size() == 1) {

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
@ -101,7 +102,7 @@ public class ConditionRouter extends AbstractRouter implements Comparable<Router
String separator = matcher.group(1);
String content = matcher.group(2);
// Start part of the condition expression.
if (separator == null || separator.length() == 0) {
if (StringUtils.isEmpty(separator)) {
pair = new MatchPair();
condition.put(content, pair);
}
@ -163,7 +164,7 @@ public class ConditionRouter extends AbstractRouter implements Comparable<Router
return invokers;
}
if (invokers == null || invokers.isEmpty()) {
if (CollectionUtils.isEmpty(invokers)) {
return invokers;
}
try {
@ -205,11 +206,11 @@ public class ConditionRouter extends AbstractRouter implements Comparable<Router
}
boolean matchWhen(URL url, Invocation invocation) {
return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation);
return CollectionUtils.isEmptyMap(whenCondition) || matchCondition(whenCondition, url, null, invocation);
}
private boolean matchThen(URL url, URL param) {
return !(thenCondition == null || thenCondition.isEmpty()) && matchCondition(thenCondition, url, param, null);
return CollectionUtils.isNotEmptyMap(thenCondition) && matchCondition(thenCondition, url, param, null);
}
private boolean matchCondition(Map<String, MatchPair> condition, URL url, URL param, Invocation invocation) {

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcContext;
@ -58,10 +59,10 @@ public class ScriptRouter extends AbstractRouter {
String type = url.getParameter(Constants.TYPE_KEY);
this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
String rule = url.getParameterAndDecoded(Constants.RULE_KEY);
if (type == null || type.length() == 0) {
if (StringUtils.isEmpty(type)) {
type = Constants.DEFAULT_SCRIPT_TYPE_KEY;
}
if (rule == null || rule.length() == 0) {
if (StringUtils.isEmpty(rule)) {
throw new IllegalStateException("route rule can not be empty. rule:" + rule);
}
ScriptEngine engine = engines.get(type);

View File

@ -181,7 +181,7 @@ public class TagRouter extends AbstractRouter implements Comparable<Router>, Con
@Override
public <T> void notify(List<Invoker<T>> invokers) {
if (invokers == null || invokers.isEmpty()) {
if (CollectionUtils.isEmpty(invokers)) {
return;
}

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
@ -103,7 +104,7 @@ public class MockClusterInvoker<T> implements Invoker<T> {
Invoker<T> minvoker;
List<Invoker<T>> mockInvokers = selectMockInvoker(invocation);
if (mockInvokers == null || mockInvokers.isEmpty()) {
if (CollectionUtils.isEmpty(mockInvokers)) {
minvoker = (Invoker<T>) new MockInvoker(directory.getUrl());
} else {
minvoker = mockInvokers.get(0);

View File

@ -96,13 +96,13 @@ public class Parameters {
public String getParameter(String key) {
String value = parameters.get(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = parameters.get(Constants.HIDE_KEY_PREFIX + key);
}
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
}
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = parameters.get(Constants.HIDE_KEY_PREFIX + Constants.DEFAULT_KEY_PREFIX + key);
}
return value;
@ -110,7 +110,7 @@ public class Parameters {
public String getParameter(String key, String defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
@ -118,7 +118,7 @@ public class Parameters {
public int getIntParameter(String key) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return 0;
}
return Integer.parseInt(value);
@ -126,7 +126,7 @@ public class Parameters {
public int getIntParameter(String key, int defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Integer.parseInt(value);
@ -137,7 +137,7 @@ public class Parameters {
throw new IllegalArgumentException("defaultValue <= 0");
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
int i = Integer.parseInt(value);
@ -149,7 +149,7 @@ public class Parameters {
public boolean getBooleanParameter(String key) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return false;
}
return Boolean.parseBoolean(value);
@ -157,7 +157,7 @@ public class Parameters {
public boolean getBooleanParameter(String key, boolean defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Boolean.parseBoolean(value);
@ -170,10 +170,10 @@ public class Parameters {
public String getMethodParameter(String method, String key) {
String value = parameters.get(method + "." + key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = parameters.get(Constants.HIDE_KEY_PREFIX + method + "." + key);
}
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return getParameter(key);
}
return value;
@ -181,7 +181,7 @@ public class Parameters {
public String getMethodParameter(String method, String key, String defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
@ -189,7 +189,7 @@ public class Parameters {
public int getMethodIntParameter(String method, String key) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return 0;
}
return Integer.parseInt(value);
@ -197,7 +197,7 @@ public class Parameters {
public int getMethodIntParameter(String method, String key, int defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Integer.parseInt(value);
@ -208,7 +208,7 @@ public class Parameters {
throw new IllegalArgumentException("defaultValue <= 0");
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
int i = Integer.parseInt(value);
@ -220,7 +220,7 @@ public class Parameters {
public boolean getMethodBooleanParameter(String method, String key) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return false;
}
return Boolean.parseBoolean(value);
@ -228,7 +228,7 @@ public class Parameters {
public boolean getMethodBooleanParameter(String method, String key, boolean defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Boolean.parseBoolean(value);

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.common;
import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.InmemoryConfiguration;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
@ -70,7 +71,8 @@ import java.util.concurrent.ConcurrentHashMap;
* @see java.net.URL
* @see java.net.URI
*/
public /**final**/ class URL implements Serializable {
public /**final**/
class URL implements Serializable {
private static final long serialVersionUID = -1985165475234910535L;
@ -149,8 +151,8 @@ public /**final**/ class URL implements Serializable {
}
public URL(String protocol, String username, String password, String host, int port, String path, Map<String, String> parameters) {
if ((username == null || username.length() == 0)
&& password != null && password.length() > 0) {
if (StringUtils.isEmpty(username)
&& StringUtils.isNotEmpty(password)) {
throw new IllegalArgumentException("Invalid url, password without username!");
}
this.protocol = protocol;
@ -248,7 +250,7 @@ public /**final**/ class URL implements Serializable {
// see https://howdoesinternetwork.com/2013/ipv6-zone-id
// ignore
} else {
port = Integer.parseInt(url.substring(i+1));
port = Integer.parseInt(url.substring(i + 1));
url = url.substring(0, i);
}
}
@ -300,7 +302,7 @@ public /**final**/ class URL implements Serializable {
}
public static String encode(String value) {
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return "";
}
try {
@ -311,7 +313,7 @@ public /**final**/ class URL implements Serializable {
}
public static String decode(String value) {
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return "";
}
try {
@ -346,8 +348,8 @@ public /**final**/ class URL implements Serializable {
}
public String getAuthority() {
if ((username == null || username.length() == 0)
&& (password == null || password.length() == 0)) {
if (StringUtils.isEmpty(username)
&& StringUtils.isEmpty(parameter)) {
return null;
}
return (username == null ? "" : username)
@ -364,7 +366,7 @@ public /**final**/ class URL implements Serializable {
/**
* Fetch IP address for this URL.
*
* <p>
* Pls. note that IP should be used instead of Host when to compare with socket's address or to search in a map
* which use address as its key.
*
@ -413,7 +415,7 @@ public /**final**/ class URL implements Serializable {
public String getBackupAddress(int defaultPort) {
StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort));
String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
if (ArrayUtils.isNotEmpty(backups)) {
for (String backup : backups) {
address.append(",");
address.append(appendDefaultPort(backup, defaultPort));
@ -476,7 +478,7 @@ public /**final**/ class URL implements Serializable {
public String getParameter(String key) {
String value = parameters.get(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
}
return value;
@ -484,7 +486,7 @@ public /**final**/ class URL implements Serializable {
public String getParameter(String key, String defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
@ -492,7 +494,7 @@ public /**final**/ class URL implements Serializable {
public String[] getParameter(String key, String[] defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Constants.COMMA_SPLIT_PATTERN.split(value);
@ -518,7 +520,7 @@ public /**final**/ class URL implements Serializable {
return u;
}
String value = getParameterAndDecoded(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return null;
}
u = URL.valueOf(value);
@ -532,7 +534,7 @@ public /**final**/ class URL implements Serializable {
return n.doubleValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
double d = Double.parseDouble(value);
@ -546,7 +548,7 @@ public /**final**/ class URL implements Serializable {
return n.floatValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
float f = Float.parseFloat(value);
@ -560,7 +562,7 @@ public /**final**/ class URL implements Serializable {
return n.longValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
long l = Long.parseLong(value);
@ -574,7 +576,7 @@ public /**final**/ class URL implements Serializable {
return n.intValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
int i = Integer.parseInt(value);
@ -588,7 +590,7 @@ public /**final**/ class URL implements Serializable {
return n.shortValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
short s = Short.parseShort(value);
@ -602,7 +604,7 @@ public /**final**/ class URL implements Serializable {
return n.byteValue();
}
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
byte b = Byte.parseByte(value);
@ -678,7 +680,7 @@ public /**final**/ class URL implements Serializable {
public char getParameter(String key, char defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value.charAt(0);
@ -686,7 +688,7 @@ public /**final**/ class URL implements Serializable {
public boolean getParameter(String key, boolean defaultValue) {
String value = getParameter(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Boolean.parseBoolean(value);
@ -707,7 +709,7 @@ public /**final**/ class URL implements Serializable {
public String getMethodParameter(String method, String key) {
String value = parameters.get(method + "." + key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return getParameter(key);
}
return value;
@ -715,7 +717,7 @@ public /**final**/ class URL implements Serializable {
public String getMethodParameter(String method, String key, String defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
@ -728,7 +730,7 @@ public /**final**/ class URL implements Serializable {
return n.intValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
double d = Double.parseDouble(value);
@ -743,7 +745,7 @@ public /**final**/ class URL implements Serializable {
return n.intValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
float f = Float.parseFloat(value);
@ -758,7 +760,7 @@ public /**final**/ class URL implements Serializable {
return n.intValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
long l = Long.parseLong(value);
@ -773,7 +775,7 @@ public /**final**/ class URL implements Serializable {
return n.intValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
int i = Integer.parseInt(value);
@ -788,7 +790,7 @@ public /**final**/ class URL implements Serializable {
return n.shortValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
short s = Short.parseShort(value);
@ -803,7 +805,7 @@ public /**final**/ class URL implements Serializable {
return n.byteValue();
}
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
byte b = Byte.parseByte(value);
@ -879,7 +881,7 @@ public /**final**/ class URL implements Serializable {
public char getMethodParameter(String method, String key, char defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value.charAt(0);
@ -887,7 +889,7 @@ public /**final**/ class URL implements Serializable {
public boolean getMethodParameter(String method, String key, boolean defaultValue) {
String value = getMethodParameter(method, key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return Boolean.parseBoolean(value);
@ -925,7 +927,7 @@ public /**final**/ class URL implements Serializable {
}
public URL addParameterAndEncoded(String key, String value) {
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return this;
}
return addParameter(key, encode(value));
@ -985,8 +987,8 @@ public /**final**/ class URL implements Serializable {
}
public URL addParameter(String key, String value) {
if (key == null || key.length() == 0
|| value == null || value.length() == 0) {
if (StringUtils.isEmpty(key)
|| StringUtils.isEmpty(value)) {
return this;
}
// if value doesn't change, return immediately
@ -1000,8 +1002,8 @@ public /**final**/ class URL implements Serializable {
}
public URL addParameterIfAbsent(String key, String value) {
if (key == null || key.length() == 0
|| value == null || value.length() == 0) {
if (StringUtils.isEmpty(key)
|| StringUtils.isEmpty(value)) {
return this;
}
if (hasParameter(key)) {
@ -1019,7 +1021,7 @@ public /**final**/ class URL implements Serializable {
* @return A new URL
*/
public URL addParameters(Map<String, String> parameters) {
if (parameters == null || parameters.size() == 0) {
if (CollectionUtils.isEmptyMap(parameters)) {
return this;
}
@ -1049,7 +1051,7 @@ public /**final**/ class URL implements Serializable {
}
public URL addParametersIfAbsent(Map<String, String> parameters) {
if (parameters == null || parameters.size() == 0) {
if (CollectionUtils.isEmptyMap(parameters)) {
return this;
}
Map<String, String> map = new HashMap<String, String>(parameters);
@ -1073,21 +1075,21 @@ public /**final**/ class URL implements Serializable {
}
public URL addParameterString(String query) {
if (query == null || query.length() == 0) {
if (StringUtils.isEmpty(query)) {
return this;
}
return addParameters(StringUtils.parseQueryString(query));
}
public URL removeParameter(String key) {
if (key == null || key.length() == 0) {
if (StringUtils.isEmpty(key)) {
return this;
}
return removeParameters(key);
}
public URL removeParameters(Collection<String> keys) {
if (keys == null || keys.isEmpty()) {
if (CollectionUtils.isEmpty(keys)) {
return this;
}
return removeParameters(keys.toArray(new String[0]));
@ -1204,8 +1206,8 @@ public /**final**/ class URL implements Serializable {
}
private void buildParameters(StringBuilder buf, boolean concat, String[] parameters) {
if (getParameters() != null && getParameters().size() > 0) {
List<String> includes = (parameters == null || parameters.length == 0 ? null : Arrays.asList(parameters));
if (CollectionUtils.isNotEmptyMap(getParameters())) {
List<String> includes = (ArrayUtils.isEmpty(parameters) ? null : Arrays.asList(parameters));
boolean first = true;
for (Map.Entry<String, String> entry : new TreeMap<String, String>(getParameters()).entrySet()) {
if (entry.getKey() != null && entry.getKey().length() > 0
@ -1232,11 +1234,11 @@ public /**final**/ class URL implements Serializable {
private String buildString(boolean appendUser, boolean appendParameter, boolean useIP, boolean useService, String... parameters) {
StringBuilder buf = new StringBuilder();
if (protocol != null && protocol.length() > 0) {
if (StringUtils.isNotEmpty(protocol)) {
buf.append(protocol);
buf.append("://");
}
if (appendUser && username != null && username.length() > 0) {
if (appendUser && StringUtils.isNotEmpty(username)) {
buf.append(username);
if (password != null && password.length() > 0) {
buf.append(":");

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.common;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ClassHelper;
import org.apache.dubbo.common.utils.StringUtils;
import java.net.URL;
import java.security.CodeSource;
@ -63,7 +64,7 @@ public final class Version {
}
public static boolean isSupportResponseAttachment(String version) {
if (version == null || version.length() == 0) {
if (StringUtils.isEmpty(version)) {
return false;
}
// for previous dubbo version(2.0.10/020010~2.6.2/020602), this version is the jar's version, so they need to be ignore
@ -124,10 +125,10 @@ public final class Version {
try {
// find version info from MANIFEST.MF first
String version = cls.getPackage().getImplementationVersion();
if (version == null || version.length() == 0) {
if (StringUtils.isEmpty(version)) {
version = cls.getPackage().getSpecificationVersion();
}
if (version == null || version.length() == 0) {
if (StringUtils.isEmpty(version)) {
// guess version fro jar file name if nothing's found from MANIFEST.MF
CodeSource codeSource = cls.getProtectionDomain().getCodeSource();
if (codeSource == null) {
@ -157,7 +158,7 @@ public final class Version {
}
}
// return default version if no version info is found
return version == null || version.length() == 0 ? defaultVersion : version;
return StringUtils.isEmpty(version) ? defaultVersion : version;
} catch (Throwable e) {
// return default version when any exception is thrown
logger.error("return default version, ignore exception " + e.getMessage(), e);

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.common.bytecode;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ClassHelper;
import org.apache.dubbo.common.utils.ReflectUtils;
@ -29,6 +30,7 @@ import javassist.CtNewConstructor;
import javassist.CtNewMethod;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import org.apache.dubbo.common.utils.StringUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@ -165,7 +167,7 @@ public final class ClassGenerator {
StringBuilder sb = new StringBuilder();
sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(type)).append(' ');
sb.append(name);
if (def != null && def.length() > 0) {
if (StringUtils.isNotEmpty(def)) {
sb.append('=');
sb.append(def);
}
@ -198,7 +200,7 @@ public final class ClassGenerator {
sb.append(" arg").append(i);
}
sb.append(')');
if (ets != null && ets.length > 0) {
if (ArrayUtils.isNotEmpty(ets)) {
sb.append(" throws ");
for (int i = 0; i < ets.length; i++) {
if (i > 0) {
@ -250,7 +252,7 @@ public final class ClassGenerator {
sb.append(" arg").append(i);
}
sb.append(')');
if (ets != null && ets.length > 0) {
if (ArrayUtils.isNotEmpty(ets)) {
sb.append(" throws ");
for (int i = 0; i < ets.length; i++) {
if (i > 0) {

View File

@ -16,6 +16,8 @@
*/
package org.apache.dubbo.common.compiler.support;
import org.apache.dubbo.common.utils.StringUtils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Array;
@ -291,7 +293,7 @@ public class ClassUtils {
}
public static boolean isBeforeJava5(String javaVersion) {
return (javaVersion == null || javaVersion.length() == 0 || "1.0".equals(javaVersion)
return (StringUtils.isEmpty(javaVersion) || "1.0".equals(javaVersion)
|| "1.1".equals(javaVersion) || "1.2".equals(javaVersion)
|| "1.3".equals(javaVersion) || "1.4".equals(javaVersion));
}

View File

@ -27,7 +27,7 @@ import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.Holder;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
@ -187,7 +187,7 @@ public class ExtensionLoader<T> {
*/
public List<T> getActivateExtension(URL url, String key, String group) {
String value = url.getParameter(key);
return getActivateExtension(url, value == null || value.length() == 0 ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group);
return getActivateExtension(url, StringUtils.isEmpty(value) ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group);
}
/**
@ -253,7 +253,7 @@ public class ExtensionLoader<T> {
}
private boolean isMatchGroup(String group, String[] groups) {
if (group == null || group.length() == 0) {
if (StringUtils.isEmpty(group)) {
return true;
}
if (groups != null && groups.length > 0) {
@ -293,7 +293,7 @@ public class ExtensionLoader<T> {
*/
@SuppressWarnings("unchecked")
public T getLoadedExtension(String name) {
if (name == null || name.length() == 0) {
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("Extension name == null");
}
Holder<Object> holder = cachedInstances.get(name);
@ -325,7 +325,7 @@ public class ExtensionLoader<T> {
*/
@SuppressWarnings("unchecked")
public T getExtension(String name) {
if (name == null || name.length() == 0) {
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("Extension name == null");
}
if ("true".equals(name)) {
@ -362,7 +362,7 @@ public class ExtensionLoader<T> {
}
public boolean hasExtension(String name) {
if (name == null || name.length() == 0) {
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("Extension name == null");
}
Class<?> c = this.getExtensionClass(name);
@ -528,7 +528,7 @@ public class ExtensionLoader<T> {
}
injectExtension(instance);
Set<Class<?>> wrapperClasses = cachedWrapperClasses;
if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
if (CollectionUtils.isNotEmpty(wrapperClasses)) {
for (Class<?> wrapperClass : wrapperClasses) {
instance = injectExtension((T) wrapperClass.getConstructor(type).newInstance(instance));
}
@ -709,7 +709,7 @@ public class ExtensionLoader<T> {
wrappers.add(clazz);
} else {
clazz.getConstructor();
if (name == null || name.length() == 0) {
if (StringUtils.isEmpty(name)) {
name = findAnnotationName(clazz);
if (name.length() == 0) {
throw new IllegalStateException("No such extension name for the class " + clazz.getName() + " in the config " + resourceURL);

View File

@ -55,7 +55,7 @@ public class CollectionUtils {
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> List<T> sort(List<T> list) {
if (list != null && !list.isEmpty()) {
if (isNotEmpty(list)) {
Collections.sort((List) list);
}
return list;
@ -120,7 +120,7 @@ public class CollectionUtils {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
list.add(key);
} else {
list.add(key + separator + value);
@ -206,7 +206,15 @@ public class CollectionUtils {
}
public static boolean isNotEmpty(Collection<?> collection) {
return collection != null && !collection.isEmpty();
return !isEmpty(collection);
}
public static boolean isEmptyMap(Map map) {
return map == null || map.size() == 0;
}
public static boolean isNotEmptyMap(Map map) {
return !isEmptyMap(map);
}
}

View File

@ -50,7 +50,7 @@ public class ConfigUtils {
}
public static boolean isEmpty(String value) {
return value == null || value.length() == 0
return StringUtils.isEmpty(value)
|| "false".equalsIgnoreCase(value)
|| "0".equalsIgnoreCase(value)
|| "null".equalsIgnoreCase(value)
@ -190,7 +190,7 @@ public class ConfigUtils {
*/
public static String getSystemProperty(String key) {
String value = System.getenv(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
value = System.getProperty(key);
}
return value;

View File

@ -126,7 +126,7 @@ public class UrlUtils {
String defaultValue = entry.getValue();
if (defaultValue != null && defaultValue.length() > 0) {
String value = parameters.get(key);
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
changed = true;
parameters.put(key, defaultValue);
}
@ -318,7 +318,7 @@ public class UrlUtils {
//compatible for dubbo-2.0.0
public static List<String> revertForbid(List<String> forbid, Set<URL> subscribed) {
if (forbid != null && !forbid.isEmpty()) {
if (CollectionUtils.isNotEmpty(forbid)) {
List<String> newForbid = new ArrayList<String>();
for (String serviceName : forbid) {
if (!serviceName.contains(":") && !serviceName.contains("/")) {
@ -410,12 +410,10 @@ public class UrlUtils {
if ("*".equals(pattern)) {
return true;
}
if ((pattern == null || pattern.length() == 0)
&& (value == null || value.length() == 0)) {
if (StringUtils.isEmpty(pattern) && StringUtils.isEmpty(value)) {
return true;
}
if ((pattern == null || pattern.length() == 0)
|| (value == null || value.length() == 0)) {
if (StringUtils.isEmpty(pattern) || StringUtils.isEmpty(value)) {
return false;
}

View File

@ -774,7 +774,7 @@ public class PojoUtilsTest {
}
public void setList(List<Child> list) {
if (list != null && !list.isEmpty()) {
if (CollectionUtils.isNotEmpty(list)) {
this.list.addAll(list);
}
}
@ -784,7 +784,7 @@ public class PojoUtilsTest {
}
public void setChildren(Map<String, Child> children) {
if (children != null && !children.isEmpty()) {
if (CollectionUtils.isNotEmptyMap(children)) {
this.children.putAll(children);
}
}

View File

@ -18,6 +18,7 @@
package com.alibaba.dubbo.common;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import java.net.InetSocketAddress;
import java.util.Collection;
@ -403,7 +404,7 @@ public class URL extends org.apache.dubbo.common.URL {
@Override
public URL addParameterAndEncoded(String key, String value) {
if (value == null || value.length() == 0) {
if (StringUtils.isEmpty(value)) {
return this;
}
return addParameter(key, encode(value));

View File

@ -359,7 +359,7 @@ public abstract class AbstractConfig implements Serializable {
}
protected static void checkParameterName(Map<String, String> parameters) {
if (parameters == null || parameters.size() == 0) {
if (CollectionUtils.isEmptyMap(parameters)) {
return;
}
for (Map.Entry<String, String> entry : parameters.entrySet()) {

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.metadata.integration.MetadataReportService;
import org.apache.dubbo.monitor.MonitorFactory;
@ -242,7 +243,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
checkRegistry();
checkRegistryDataConfig();
List<URL> registryList = new ArrayList<URL>();
if (registries != null && !registries.isEmpty()) {
if (CollectionUtils.isNotEmpty(registries)) {
Map<String, String> registryDataConfigurationMap = new HashMap<>(4);
appendParameters(registryDataConfigurationMap, registryDataConfig);
for (RegistryConfig config : registries) {
@ -291,7 +292,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
appendRuntimeParameters(map);
//set ip
String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY);
if (hostToRegistry == null || hostToRegistry.length() == 0) {
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
} else if (NetUtils.isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" +
@ -332,7 +333,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
private URL loadMetadataReporterURL(boolean provider) {
this.checkApplication();
String address = metadataReportConfig.getAddress();
if (address == null || address.length() == 0) {
if (StringUtils.isEmpty(address)) {
return null;
}
Map<String, String> map = new HashMap<String, String>();
@ -367,13 +368,13 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!");
}
// check if methods exist in the remote service interface
if (methods != null && !methods.isEmpty()) {
if (CollectionUtils.isNotEmpty(methods)) {
for (MethodConfig methodBean : methods) {
methodBean.setService(interfaceClass.getName());
methodBean.setServiceId(this.getId());
methodBean.refresh();
String methodName = methodBean.getName();
if (methodName == null || methodName.length() == 0) {
if (StringUtils.isEmpty(methodName)) {
throw new IllegalStateException("<dubbo:method> name attribute is required! Please check: " +
"<dubbo:service interface=\"" + interfaceClass.getName() + "\" ... >" +
"<dubbo:method name=\"\" ... /></<dubbo:reference>");
@ -472,7 +473,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
private void convertRegistryIdsToRegistries() {
if (StringUtils.isEmpty(registryIds) && (registries == null || registries.isEmpty())) {
if (StringUtils.isEmpty(registryIds) && CollectionUtils.isEmpty(registries)) {
Set<String> configedRegistries = new HashSet<>();
configedRegistries.addAll(getSubProperties(Environment.getInstance().getExternalConfigurationMap(),
Constants.REGISTRIES_SUFFIX));
@ -483,13 +484,13 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
if (StringUtils.isEmpty(registryIds)) {
if (registries == null || registries.isEmpty()) {
if (CollectionUtils.isEmpty(registries)) {
registries = new ArrayList<>();
registries.add(new RegistryConfig());
}
} else {
String[] arr = Constants.COMMA_SPLIT_PATTERN.split(registryIds);
if (registries == null || registries.isEmpty()) {
if (CollectionUtils.isEmpty(registries)) {
registries = new ArrayList<>();
}
Arrays.stream(arr).forEach(id -> {
@ -663,7 +664,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
}
public RegistryConfig getRegistry() {
return registries == null || registries.isEmpty() ? null : registries.get(0);
return CollectionUtils.isEmpty(registries) ? null : registries.get(0);
}
public void setRegistry(RegistryConfig registry) {

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.config;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.ExporterListener;
@ -203,7 +204,7 @@ public abstract class AbstractServiceConfig extends AbstractInterfaceConfig {
}
public ProtocolConfig getProtocol() {
return protocols == null || protocols.isEmpty() ? null : protocols.get(0);
return CollectionUtils.isEmpty(protocols) ? null : protocols.get(0);
}
public void setProtocol(ProtocolConfig protocol) {

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.config;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.compiler.support.AdaptiveCompiler;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
@ -202,7 +203,7 @@ public class ApplicationConfig extends AbstractConfig {
}
public RegistryConfig getRegistry() {
return registries == null || registries.isEmpty() ? null : registries.get(0);
return CollectionUtils.isEmpty(registries) ? null : registries.get(0);
}
public void setRegistry(RegistryConfig registry) {

View File

@ -17,6 +17,8 @@
package org.apache.dubbo.config;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
import java.util.ArrayList;
@ -81,7 +83,7 @@ public class ModuleConfig extends AbstractConfig {
public void setName(String name) {
checkName(Constants.NAME, name);
this.name = name;
if (id == null || id.length() == 0) {
if (StringUtils.isEmpty(id)) {
id = name;
}
}
@ -114,7 +116,7 @@ public class ModuleConfig extends AbstractConfig {
}
public RegistryConfig getRegistry() {
return registries == null || registries.isEmpty() ? null : registries.get(0);
return CollectionUtils.isEmpty(registries) ? null : registries.get(0);
}
public void setRegistry(RegistryConfig registry) {

View File

@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.ClassHelper;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.metadata.integration.MetadataReportService;
@ -191,7 +192,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
* Check each config modules are created properly and override their properties if necessary.
*/
public void checkAndUpdateSubConfigs() {
if (interfaceName == null || interfaceName.length() == 0) {
if (StringUtils.isEmpty(interfaceName)) {
throw new IllegalStateException("<dubbo:reference interface=\"\" /> interface not allow null!");
}
// get consumer's global configuration
@ -286,7 +287,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
appendParameters(map, consumer, Constants.DEFAULT_KEY);
appendParameters(map, this);
Map<String, Object> attributes = null;
if (methods != null && !methods.isEmpty()) {
if (CollectionUtils.isNotEmpty(methods)) {
attributes = new HashMap<String, Object>();
for (MethodConfig methodConfig : methods) {
appendParameters(map, methodConfig, methodConfig.getName());
@ -302,7 +303,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
}
String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY);
if (hostToRegistry == null || hostToRegistry.length() == 0) {
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
} else if (isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
@ -342,7 +343,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
if (us != null && us.length > 0) {
for (String u : us) {
URL url = URL.valueOf(u);
if (url.getPath() == null || url.getPath().length() == 0) {
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(interfaceName);
}
if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) {
@ -354,7 +355,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
}
} else { // assemble URL from register center's configuration
List<URL> us = loadRegistries(false);
if (us != null && !us.isEmpty()) {
if (CollectionUtils.isNotEmpty(us)) {
for (URL u : us) {
URL monitorUrl = loadMonitor(u);
if (monitorUrl != null) {
@ -493,7 +494,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
public void setInterface(String interfaceName) {
this.interfaceName = interfaceName;
if (id == null || id.length() == 0) {
if (StringUtils.isEmpty(id)) {
id = interfaceName;
}
}
@ -561,7 +562,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
buf.append(group).append("/");
}
buf.append(interfaceName);
if (version != null && version.length() > 0) {
if (StringUtils.isNotEmpty(version)) {
buf.append(":").append(version);
}
return buf.toString();
@ -576,9 +577,9 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
private void resolveFile() {
String resolve = System.getProperty(interfaceName);
String resolveFile = null;
if (resolve == null || resolve.length() == 0) {
if (StringUtils.isEmpty(resolve)) {
resolveFile = System.getProperty("dubbo.resolve.file");
if (resolveFile == null || resolveFile.length() == 0) {
if (StringUtils.isEmpty(resolveFile)) {
File userResolveFile = new File(new File(System.getProperty("user.home")), "dubbo-resolve.properties");
if (userResolveFile.exists()) {
resolveFile = userResolveFile.getAbsolutePath();

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.ClassHelper;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker;
import org.apache.dubbo.config.support.Parameter;
@ -173,7 +174,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
@Deprecated
private static List<ProtocolConfig> convertProviderToProtocol(List<ProviderConfig> providers) {
if (providers == null || providers.isEmpty()) {
if (CollectionUtils.isEmpty(providers)) {
return null;
}
List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>(providers.size());
@ -185,7 +186,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
@Deprecated
private static List<ProviderConfig> convertProtocolToProvider(List<ProtocolConfig> protocols) {
if (protocols == null || protocols.isEmpty()) {
if (CollectionUtils.isEmpty(protocols)) {
return null;
}
List<ProviderConfig> providers = new ArrayList<ProviderConfig>(protocols.size());
@ -277,7 +278,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
checkMetadataReport();
checkRegistryDataConfig();
if (interfaceName == null || interfaceName.length() == 0) {
if (StringUtils.isEmpty(interfaceName)) {
throw new IllegalStateException("<dubbo:service interface=\"\" /> interface not allow null!");
}
@ -360,7 +361,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
exported = true;
if (path == null || path.length() == 0) {
if (StringUtils.isEmpty(path)) {
path = interfaceName;
}
ProviderModel providerModel = new ProviderModel(getUniqueServiceName(), ref, interfaceClass);
@ -410,7 +411,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> registryURLs) {
String name = protocolConfig.getName();
if (name == null || name.length() == 0) {
if (StringUtils.isEmpty(name)) {
name = Constants.DUBBO;
}
@ -422,7 +423,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
appendParameters(map, provider, Constants.DEFAULT_KEY);
appendParameters(map, protocolConfig);
appendParameters(map, this);
if (methods != null && !methods.isEmpty()) {
if (CollectionUtils.isNotEmpty(methods)) {
for (MethodConfig method : methods) {
appendParameters(map, method, method.getName());
String retryKey = method.getName() + ".retry";
@ -433,7 +434,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
}
List<ArgumentConfig> arguments = method.getArguments();
if (arguments != null && !arguments.isEmpty()) {
if (CollectionUtils.isNotEmpty(arguments)) {
for (ArgumentConfig argument : arguments) {
// convert argument type
if (argument.getType() != null && argument.getType().length() > 0) {
@ -508,13 +509,13 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
// export service
String contextPath = protocolConfig.getContextpath();
if ((contextPath == null || contextPath.length() == 0) && provider != null) {
if (StringUtils.isEmpty(contextPath) && provider != null) {
contextPath = provider.getContextpath();
}
String host = this.findConfigedHosts(protocolConfig, registryURLs, map);
Integer port = this.findConfigedPorts(protocolConfig, name, map);
URL url = new URL(name, host, port, (contextPath == null || contextPath.length() == 0 ? "" : contextPath + "/") + path, map);
URL url = new URL(name, host, port, (StringUtils.isEmpty(contextPath) ? "" : contextPath + "/") + path, map);
if (ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class)
.hasExtension(url.getProtocol())) {
@ -535,7 +536,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
if (logger.isInfoEnabled()) {
logger.info("Export dubbo service " + interfaceClass.getName() + " to url " + url);
}
if (registryURLs != null && !registryURLs.isEmpty()) {
if (CollectionUtils.isNotEmpty(registryURLs)) {
for (URL registryURL : registryURLs) {
url = url.addParameterIfAbsent(Constants.DYNAMIC_KEY, registryURL.getParameter(Constants.DYNAMIC_KEY));
URL monitorUrl = loadMonitor(registryURL);
@ -651,9 +652,9 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
// if bind ip is not found in environment, keep looking up
if (hostToBind == null || hostToBind.length() == 0) {
if (StringUtils.isEmpty(hostToBind)) {
hostToBind = protocolConfig.getHost();
if (provider != null && (hostToBind == null || hostToBind.length() == 0)) {
if (provider != null && StringUtils.isEmpty(hostToBind)) {
hostToBind = provider.getHost();
}
if (isInvalidLocalHost(hostToBind)) {
@ -664,7 +665,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
logger.warn(e.getMessage(), e);
}
if (isInvalidLocalHost(hostToBind)) {
if (registryURLs != null && !registryURLs.isEmpty()) {
if (CollectionUtils.isNotEmpty(registryURLs)) {
for (URL registryURL : registryURLs) {
if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter("registry"))) {
// skip multicast registry since we cannot connect to it via Socket
@ -701,7 +702,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
String hostToRegistry = getValueFromConfig(protocolConfig, Constants.DUBBO_IP_TO_REGISTRY);
if (hostToRegistry != null && hostToRegistry.length() > 0 && isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
} else if (hostToRegistry == null || hostToRegistry.length() == 0) {
} else if (StringUtils.isEmpty(hostToRegistry)) {
// bind ip is used as registry ip by default
hostToRegistry = hostToBind;
}
@ -778,7 +779,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
private String getValueFromConfig(ProtocolConfig protocolConfig, String key) {
String protocolPrefix = protocolConfig.getName().toUpperCase() + "_";
String port = ConfigUtils.getSystemProperty(protocolPrefix + key);
if (port == null || port.length() == 0) {
if (StringUtils.isEmpty(port)) {
port = ConfigUtils.getSystemProperty(key);
}
return port;
@ -792,7 +793,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
private void checkProtocol() {
if ((protocols == null || protocols.isEmpty()) && provider != null) {
if (CollectionUtils.isEmpty(protocols) && provider != null) {
setProtocols(provider.getProtocols());
}
@ -811,7 +812,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
private void convertProtocolIdsToProtocols() {
if (StringUtils.isEmpty(protocolIds) && (protocols == null || protocols.isEmpty())) {
if (StringUtils.isEmpty(protocolIds) && CollectionUtils.isEmpty(protocols)) {
List<String> configedProtocols = new ArrayList<>();
configedProtocols.addAll(getSubProperties(Environment.getInstance()
.getExternalConfigurationMap(), Constants.PROTOCOLS_SUFFIX));
@ -822,13 +823,13 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
}
if (StringUtils.isEmpty(protocolIds)) {
if (protocols == null || protocols.isEmpty()) {
if (CollectionUtils.isEmpty(protocols)) {
protocols = new ArrayList<>();
protocols.add(new ProtocolConfig());
}
} else {
String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds);
if (protocols == null || protocols.isEmpty()) {
if (CollectionUtils.isEmpty(protocols)) {
protocols = new ArrayList<>();
}
Arrays.stream(arr).forEach(id -> {
@ -886,7 +887,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
public void setInterface(String interfaceName) {
this.interfaceName = interfaceName;
if (id == null || id.length() == 0) {
if (StringUtils.isEmpty(id)) {
id = interfaceName;
}
}

View File

@ -19,8 +19,10 @@ package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.AbstractConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConsumerConfig;
@ -74,7 +76,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be
public void setPackage(String annotationPackage) {
this.annotationPackage = annotationPackage;
this.annotationPackages = (annotationPackage == null || annotationPackage.length() == 0) ? null
this.annotationPackages = (StringUtils.isEmpty(annotationPackage)) ? null
: Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
}
@ -86,7 +88,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
if (annotationPackage == null || annotationPackage.length() == 0) {
if (StringUtils.isEmpty(annotationPackage)) {
return;
}
if (beanFactory instanceof BeanDefinitionRegistry) {
@ -306,7 +308,7 @@ public class AnnotationBean extends AbstractConfig implements DisposableBean, Be
}
private boolean isMatchPackage(Object bean) {
if (annotationPackages == null || annotationPackages.length == 0) {
if (ArrayUtils.isEmpty(annotationPackages)) {
return true;
}
String beanClassName = bean.getClass().getName();

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
@ -78,7 +79,7 @@ public class ConfigCenterBean extends ConfigCenterConfig implements Initializing
if ((getRegistry() == null)) {
List<RegistryConfig> registryConfigs = new ArrayList<>();
if (getApplication() != null && getApplication().getRegistries() != null && !getApplication().getRegistries().isEmpty()) {
if (getApplication() != null && CollectionUtils.isNotEmpty(getApplication().getRegistries())) {
registryConfigs = getApplication().getRegistries();
} else {
Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false);

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConsumerConfig;
@ -151,9 +152,9 @@ public class ReferenceBean<T> extends ReferenceConfig<T> implements FactoryBean,
}
}
if ((getRegistries() == null || getRegistries().isEmpty())
&& (getConsumer() == null || getConsumer().getRegistries() == null || getConsumer().getRegistries().isEmpty())
&& (getApplication() == null || getApplication().getRegistries() == null || getApplication().getRegistries().isEmpty())) {
if (CollectionUtils.isEmpty(getRegistries())
&& (getConsumer() == null || CollectionUtils.isEmpty(getConsumer().getRegistries()))
&& (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) {
Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false);
if (registryConfigMap != null && registryConfigMap.size() > 0) {
List<RegistryConfig> registryConfigs = new ArrayList<>();

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
@ -112,7 +113,7 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
Map<String, ProviderConfig> providerConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProviderConfig.class, false, false);
if (providerConfigMap != null && providerConfigMap.size() > 0) {
Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false);
if ((protocolConfigMap == null || protocolConfigMap.size() == 0)
if (CollectionUtils.isEmptyMap(protocolConfigMap)
&& providerConfigMap.size() > 1) { // backward compatibility
List<ProviderConfig> providerConfigs = new ArrayList<ProviderConfig>();
for (ProviderConfig config : providerConfigMap.values()) {
@ -185,11 +186,11 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
}
}
if ((getRegistries() == null || getRegistries().isEmpty())
&& (getProvider() == null || getProvider().getRegistries() == null || getProvider().getRegistries().isEmpty())
&& (getApplication() == null || getApplication().getRegistries() == null || getApplication().getRegistries().isEmpty())) {
if ((CollectionUtils.isEmpty(getRegistries()))
&& (getProvider() == null || CollectionUtils.isEmpty(getProvider().getRegistries()))
&& (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) {
Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false);
if (registryConfigMap != null && registryConfigMap.size() > 0) {
if (CollectionUtils.isNotEmptyMap(registryConfigMap)) {
List<RegistryConfig> registryConfigs = new ArrayList<>();
if (StringUtils.isNotEmpty(registryIds)) {
Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> {
@ -255,8 +256,8 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
}
}
if ((getProtocols() == null || getProtocols().isEmpty())
&& (getProvider() == null || getProvider().getProtocols() == null || getProvider().getProtocols().isEmpty())) {
if (CollectionUtils.isEmpty(getProtocols())
&& (getProvider() == null || CollectionUtils.isEmpty(getProvider().getProtocols()))) {
Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false);
if (protocolConfigMap != null && protocolConfigMap.size() > 0) {
List<ProtocolConfig> protocolConfigs = new ArrayList<ProtocolConfig>();
@ -282,9 +283,9 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
}
}
}
if (getPath() == null || getPath().length() == 0) {
if (beanName != null && beanName.length() > 0
&& getInterface() != null && getInterface().length() > 0
if (StringUtils.isEmpty(getPath())) {
if (StringUtils.isNotEmpty(beanName)
&& StringUtils.isNotEmpty(getInterface())
&& beanName.startsWith(getInterface())) {
setPath(beanName);
}

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;
@ -582,7 +583,7 @@ public class ReferenceAnnotationBeanPostProcessor extends InstantiationAwareBean
}
private String toPlainString(String[] array) {
if (array == null || array.length == 0) {
if (ArrayUtils.isEmpty(array)) {
return "";
}
StringBuilder buffer = new StringBuilder();

View File

@ -75,16 +75,16 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
beanDefinition.setBeanClass(beanClass);
beanDefinition.setLazyInit(false);
String id = element.getAttribute("id");
if ((id == null || id.length() == 0) && required) {
if (StringUtils.isEmpty(id) && required) {
String generatedBeanName = element.getAttribute("name");
if (generatedBeanName == null || generatedBeanName.length() == 0) {
if (StringUtils.isEmpty(generatedBeanName)) {
if (ProtocolConfig.class.equals(beanClass)) {
generatedBeanName = "dubbo";
} else {
generatedBeanName = element.getAttribute("interface");
}
}
if (generatedBeanName == null || generatedBeanName.length() == 0) {
if (StringUtils.isEmpty(generatedBeanName)) {
generatedBeanName = beanClass.getName();
}
id = generatedBeanName;
@ -258,7 +258,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
if (first) {
first = false;
String isDefault = element.getAttribute("default");
if (isDefault == null || isDefault.length() == 0) {
if (StringUtils.isEmpty(isDefault)) {
beanDefinition.getPropertyValues().addPropertyValue("default", "false");
}
}
@ -335,7 +335,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
Element element = (Element) node;
if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) {
String methodName = element.getAttribute("name");
if (methodName == null || methodName.length() == 0) {
if (StringUtils.isEmpty(methodName)) {
throw new IllegalStateException("<dubbo:method> name attribute == null");
}
if (methods == null) {

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.status.Status;
import org.apache.dubbo.common.status.StatusChecker;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.spring.extension.SpringExtensionFactory;
import org.springframework.context.ApplicationContext;
@ -55,7 +56,7 @@ public class DataSourceStatusChecker implements StatusChecker {
}
Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
if (dataSources == null || dataSources.size() == 0) {
if (CollectionUtils.isEmptyMap(dataSources)) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;

View File

@ -19,6 +19,8 @@ package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.RegistryService;
@ -205,8 +207,8 @@ public abstract class AbstractRegistryService implements RegistryService {
}
protected final void notify(String service, List<URL> urls) {
if (service == null || service.length() == 0
|| urls == null || urls.size() == 0) {
if (StringUtils.isEmpty(service)
|| CollectionUtils.isEmpty(urls)) {
return;
}
doNotify(service, urls);

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.config.spring;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.registry.NotifyListener;
@ -72,7 +73,7 @@ public class SimpleRegistryService extends AbstractRegistryService {
}
List<URL> urls = getRegistered().get(service);
if ((RegistryService.class.getName() + ":0.0.0").equals(service)
&& (urls == null || urls.size() == 0)) {
&& CollectionUtils.isEmpty(urls)) {
register(service, new URL("dubbo",
NetUtils.getLocalHost(),
RpcContext.getContext().getLocalPort(),

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import java.text.SimpleDateFormat;
@ -49,7 +50,7 @@ public class Main {
public static void main(String[] args) {
try {
if (args == null || args.length == 0) {
if (ArrayUtils.isEmpty(args)) {
String config = ConfigUtils.getProperty(CONTAINER_KEY, loader.getDefaultExtensionName());
args = Constants.COMMA_SPLIT_PATTERN.split(config);
}

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.container.log4j;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.container.Container;
import org.apache.log4j.Appender;
@ -46,7 +47,7 @@ public class Log4jContainer implements Container {
String file = ConfigurationUtils.getProperty(LOG4J_FILE);
if (file != null && file.length() > 0) {
String level = ConfigurationUtils.getProperty(LOG4J_LEVEL);
if (level == null || level.length() == 0) {
if (StringUtils.isEmpty(level)) {
level = DEFAULT_LOG4J_LEVEL;
}
Properties properties = new Properties();

View File

@ -47,7 +47,7 @@ public class LogbackContainer implements Container {
String file = ConfigUtils.getProperty(LOGBACK_FILE);
if (file != null && file.length() > 0) {
String level = ConfigUtils.getProperty(LOGBACK_LEVEL);
if (level == null || level.length() == 0) {
if (StringUtils.isEmpty(level)) {
level = DEFAULT_LOGBACK_LEVEL;
}
// maxHistory=0 Infinite history

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.container.spring;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.container.Container;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -40,7 +41,7 @@ public class SpringContainer implements Container {
@Override
public void start() {
String configPath = ConfigUtils.getProperty(SPRING_CONFIG);
if (configPath == null || configPath.length() == 0) {
if (StringUtils.isEmpty(configPath)) {
configPath = DEFAULT_SPRING_CONFIG;
}
context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+"));

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.cache.support.jcache;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import javax.cache.Cache;
import javax.cache.CacheException;
@ -49,7 +50,7 @@ public class JCache implements org.apache.dubbo.cache.Cache {
// jcache parameter is the full-qualified class name of SPI implementation
String type = url.getParameter("jcache");
CachingProvider provider = type == null || type.length() == 0 ? Caching.getCachingProvider() : Caching.getCachingProvider(type);
CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type);
CacheManager cacheManager = provider.getCacheManager();
Cache<Object, Object> cache = cacheManager.getCache(key);
if (cache == null) {

View File

@ -16,6 +16,8 @@
*/
package org.apache.dubbo.metadata.definition.util;
import org.apache.dubbo.common.utils.StringUtils;
import java.io.InputStream;
import java.util.Properties;
@ -36,17 +38,17 @@ public class JaketConfigurationUtils {
try {
props.load(inStream);
String value = (String) props.get("included_interface_packages");
if (value != null && !value.isEmpty()) {
if (StringUtils.isNotEmpty(value)) {
includedInterfacePackages = value.split(",");
}
value = props.getProperty("included_type_packages");
if (value != null && !value.isEmpty()) {
if (StringUtils.isNotEmpty(value)) {
includedTypePackages = value.split(",");
}
value = props.getProperty("closed_types");
if (value != null && !value.isEmpty()) {
if (StringUtils.isNotEmpty(value)) {
closedTypes = value.split(",");
}

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.monitor.dubbo;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.monitor.Monitor;
import org.apache.dubbo.monitor.MonitorService;
import org.apache.dubbo.monitor.support.AbstractMonitorFactory;
@ -45,11 +46,11 @@ public class DubboMonitorFactory extends AbstractMonitorFactory {
@Override
protected Monitor createMonitor(URL url) {
url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
if (url.getPath() == null || url.getPath().length() == 0) {
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(MonitorService.class.getName());
}
String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
if (filter == null || filter.length() == 0) {
if (StringUtils.isEmpty(filter)) {
filter = "";
} else {
filter = filter + ",";

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
@ -44,7 +45,7 @@ public class Online implements BaseCommand {
public String execute(CommandContext commandContext, String[] args) {
logger.info("receive online command");
String servicePattern = ".*";
if (args != null && args.length > 0) {
if (ArrayUtils.isNotEmpty(args)) {
servicePattern = args[0];
}

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.qos.command;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.qos.command.annotation.Cmd;
@ -24,6 +25,6 @@ import org.apache.dubbo.qos.command.annotation.Cmd;
public class GreetingCommand implements BaseCommand {
@Override
public String execute(CommandContext commandContext, String[] args) {
return args != null && args.length > 0 ? "greeting " + args[0] : "greeting";
return ArrayUtils.isNotEmpty(args) ? "greeting " + args[0] : "greeting";
}
}

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
@ -242,7 +243,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
// state change
// If the calculation is wrong, it is not processed.
if (newUrlInvokerMap == null || newUrlInvokerMap.size() == 0) {
if (CollectionUtils.isEmptyMap(newUrlInvokerMap)) {
logger.error(new IllegalStateException("urls to invokers error .invokerUrls.size :" + invokerUrls.size() + ", invoker.size :0. urls :" + invokerUrls
.toString()));
return;
@ -442,7 +443,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
private URL overrideWithConfigurators(List<Configurator> configurators, URL url) {
if (configurators != null && !configurators.isEmpty()) {
if (CollectionUtils.isNotEmpty(configurators)) {
for (Configurator configurator : configurators) {
url = configurator.configure(url);
}
@ -626,7 +627,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
private void doOverrideUrl(List<Configurator> configurators) {
if (configurators != null && !configurators.isEmpty()) {
if (CollectionUtils.isNotEmpty(configurators)) {
for (Configurator configurator : configurators) {
this.overrideDirectoryUrl = configurator.configure(overrideDirectoryUrl);
}

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
@ -120,7 +121,7 @@ public class RegistryProtocol implements Protocol {
//Filter the parameters that do not need to be output in url(Starting with .)
private static String[] getFilteredKeys(URL url) {
Map<String, String> params = url.getParameters();
if (params != null && !params.isEmpty()) {
if (CollectionUtils.isNotEmptyMap(params)) {
return params.keySet().stream()
.filter(k -> k.startsWith(HIDE_KEY_PREFIX))
.toArray(String[]::new);

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
@ -248,7 +249,7 @@ public abstract class AbstractRegistry implements Registry {
NotifyListener listener = reference::set;
subscribe(url, listener); // Subscribe logic guarantees the first notify to return
List<URL> urls = reference.get();
if (urls != null && !urls.isEmpty()) {
if (CollectionUtils.isNotEmpty(urls)) {
for (URL u : urls) {
if (!Constants.EMPTY_PROTOCOL.equals(u.getProtocol())) {
result.add(u);

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.registry.support;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.timer.HashedWheelTimer;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.retry.FailedNotifiedTask;
@ -291,7 +292,7 @@ public abstract class FailbackRegistry extends AbstractRegistry {
Throwable t = e;
List<URL> urls = getCacheUrls(url);
if (urls != null && !urls.isEmpty()) {
if (CollectionUtils.isNotEmpty(urls)) {
notify(url, listener, urls);
logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t);
} else {

View File

@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.support.FailbackRegistry;
@ -204,7 +205,7 @@ public class MulticastRegistry extends FailbackRegistry {
} else if (msg.startsWith(Constants.SUBSCRIBE)) {
URL url = URL.valueOf(msg.substring(Constants.SUBSCRIBE.length()).trim());
Set<URL> urls = getRegistered();
if (urls != null && !urls.isEmpty()) {
if (CollectionUtils.isNotEmpty(urls)) {
for (URL u : urls) {
if (UrlUtils.isMatch(url, u)) {
String host = remoteAddress != null && remoteAddress.getAddress() != null
@ -363,7 +364,7 @@ public class MulticastRegistry extends FailbackRegistry {
private List<URL> toList(Set<URL> urls) {
List<URL> list = new ArrayList<URL>();
if (urls != null && !urls.isEmpty()) {
if (CollectionUtils.isNotEmpty(urls)) {
for (URL url : urls) {
list.add(url);
}
@ -406,7 +407,7 @@ public class MulticastRegistry extends FailbackRegistry {
}
if (urls.isEmpty()) {
List<URL> cacheUrls = getCacheUrls(url);
if (cacheUrls != null && !cacheUrls.isEmpty()) {
if (CollectionUtils.isNotEmpty(cacheUrls)) {
urls.addAll(cacheUrls);
}
}

View File

@ -24,6 +24,8 @@ import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.support.FailbackRegistry;
import org.apache.dubbo.rpc.RpcException;
@ -53,7 +55,6 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* RedisRegistry
*
*/
public class RedisRegistry extends FailbackRegistry {
@ -124,7 +125,7 @@ public class RedisRegistry extends FailbackRegistry {
List<String> addresses = new ArrayList<String>();
addresses.add(url.getAddress());
String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
if (ArrayUtils.isNotEmpty(backups)) {
addresses.addAll(Arrays.asList(backups));
}
@ -199,10 +200,10 @@ public class RedisRegistry extends FailbackRegistry {
// The monitoring center is responsible for deleting outdated dirty data
private void clean(Jedis jedis) {
Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
if (keys != null && !keys.isEmpty()) {
if (CollectionUtils.isNotEmpty(keys)) {
for (String key : keys) {
Map<String, String> values = jedis.hgetAll(key);
if (values != null && values.size() > 0) {
if (CollectionUtils.isNotEmptyMap(values)) {
boolean delete = false;
long now = System.currentTimeMillis();
for (Map.Entry<String, String> entry : values.entrySet()) {
@ -359,7 +360,7 @@ public class RedisRegistry extends FailbackRegistry {
if (service.endsWith(Constants.ANY_VALUE)) {
admin = true;
Set<String> keys = jedis.keys(service);
if (keys != null && !keys.isEmpty()) {
if (CollectionUtils.isNotEmpty(keys)) {
Map<String, Set<String>> serviceKeys = new HashMap<>();
for (String key : keys) {
String serviceKey = toServicePath(key);
@ -427,7 +428,7 @@ public class RedisRegistry extends FailbackRegistry {
}
List<URL> urls = new ArrayList<>();
Map<String, String> values = jedis.hgetAll(key);
if (values != null && values.size() > 0) {
if (CollectionUtils.isEmptyMap(values)) {
for (Map.Entry<String, String> entry : values.entrySet()) {
URL u = URL.valueOf(entry.getKey());
if (!u.getParameter(Constants.DYNAMIC_KEY, true)
@ -591,7 +592,7 @@ public class RedisRegistry extends FailbackRegistry {
if (!first) {
first = false;
Set<String> keys = jedis.keys(service);
if (keys != null && !keys.isEmpty()) {
if (CollectionUtils.isNotEmpty(keys)) {
for (String s : keys) {
doNotify(jedis, s);
}

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.registry.NotifyListener;
@ -149,7 +150,7 @@ public class ZookeeperRegistry extends FailbackRegistry {
}
zkClient.create(root, false);
List<String> services = zkClient.addChildListener(root, zkListener);
if (services != null && !services.isEmpty()) {
if (CollectionUtils.isNotEmpty(services)) {
for (String service : services) {
service = URL.decode(service);
anyServices.add(service);
@ -264,7 +265,7 @@ public class ZookeeperRegistry extends FailbackRegistry {
private List<URL> toUrlsWithoutEmpty(URL consumer, List<String> providers) {
List<URL> urls = new ArrayList<>();
if (providers != null && !providers.isEmpty()) {
if (CollectionUtils.isNotEmpty(providers)) {
for (String provider : providers) {
provider = URL.decode(provider);
if (provider.contains(Constants.PROTOCOL_SEPARATOR)) {

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.timer.HashedWheelTimer;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
@ -155,7 +156,7 @@ public class HeaderExchangeServer implements ExchangeServer {
public Collection<ExchangeChannel> getExchangeChannels() {
Collection<ExchangeChannel> exchangeChannels = new ArrayList<ExchangeChannel>();
Collection<Channel> channels = server.getChannels();
if (channels != null && !channels.isEmpty()) {
if (CollectionUtils.isNotEmpty(channels)) {
for (Channel channel : channels) {
exchangeChannels.add(HeaderExchangeChannel.getOrAddChannel(channel));
}

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.RemotingException;
@ -72,7 +73,7 @@ public class TelnetCodec extends TransportCodec {
URL url = channel.getUrl();
if (url != null) {
String parameter = url.getParameter(Constants.CHARSET_KEY);
if (parameter != null && parameter.length() > 0) {
if (StringUtils.isNotEmpty(parameter)) {
try {
return Charset.forName(parameter);
} catch (Throwable t) {
@ -196,7 +197,7 @@ public class TelnetCodec extends TransportCodec {
boolean down = endsWith(message, DOWN);
if (up || down) {
LinkedList<String> history = (LinkedList<String>) channel.getAttribute(HISTORY_LIST_KEY);
if (history == null || history.isEmpty()) {
if (CollectionUtils.isEmpty(history)) {
return DecodeResult.NEED_MORE_INPUT;
}
Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY);
@ -263,7 +264,7 @@ public class TelnetCodec extends TransportCodec {
LinkedList<String> history = (LinkedList<String>) channel.getAttribute(HISTORY_LIST_KEY);
Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY);
channel.removeAttribute(HISTORY_INDEX_KEY);
if (history != null && !history.isEmpty() && index != null && index >= 0 && index < history.size()) {
if (CollectionUtils.isNotEmpty(history) && index != null && index >= 0 && index < history.size()) {
String value = history.get(index);
if (value != null) {
byte[] b1 = value.getBytes();

View File

@ -74,7 +74,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne
if (buf.length() > 0) {
buf.append("\r\n");
}
if (prompt != null && prompt.length() > 0 && !noprompt) {
if (StringUtils.isNotEmpty(prompt) && !noprompt) {
buf.append(prompt);
}
return buf.toString();

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.telnet.support.command;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.telnet.TelnetHandler;
import org.apache.dubbo.remoting.telnet.support.Help;
@ -54,7 +55,7 @@ public class HelpTelnetHandler implements TelnetHandler {
} else {
List<List<String>> table = new ArrayList<List<String>>();
List<TelnetHandler> handlers = extensionLoader.getActivateExtension(channel.getUrl(), "telnet");
if (handlers != null && !handlers.isEmpty()) {
if (CollectionUtils.isNotEmpty(handlers)) {
for (TelnetHandler handler : handlers) {
Help help = handler.getClass().getAnnotation(Help.class);
List<String> row = new ArrayList<String>();

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.status.Status;
import org.apache.dubbo.common.status.StatusChecker;
import org.apache.dubbo.common.status.support.StatusUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.telnet.TelnetHandler;
import org.apache.dubbo.remoting.telnet.support.Help;
@ -48,7 +49,7 @@ public class StatusTelnetHandler implements TelnetHandler {
String[] header = new String[]{"resource", "status", "message"};
List<List<String>> table = new ArrayList<List<String>>();
Map<String, Status> statuses = new HashMap<String, Status>();
if (checkers != null && !checkers.isEmpty()) {
if (CollectionUtils.isNotEmpty(checkers)) {
for (StatusChecker checker : checkers) {
String name = extensionLoader.getExtensionName(checker);
Status stat;
@ -79,7 +80,7 @@ public class StatusTelnetHandler implements TelnetHandler {
}
String status = channel.getUrl().getParameter("status");
Map<String, Status> statuses = new HashMap<String, Status>();
if (status != null && status.length() > 0) {
if (CollectionUtils.isNotEmptyMap(statuses)) {
String[] ss = Constants.COMMA_SPLIT_PATTERN.split(status);
for (String s : ss) {
StatusChecker handler = extensionLoader.getExtension(s);

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.common.store.DataStore;
import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Client;
@ -124,7 +125,7 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client
private static int getReconnectParam(URL url) {
int reconnect;
String param = url.getParameter(Constants.RECONNECT_KEY);
if (param == null || param.length() == 0 || "true".equalsIgnoreCase(param)) {
if (StringUtils.isEmpty(param) || "true".equalsIgnoreCase(param)) {
reconnect = Constants.DEFAULT_RECONNECT_PERIOD;
} else if ("false".equalsIgnoreCase(param)) {
reconnect = 0;

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.transport;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
@ -42,7 +43,7 @@ public class ChannelHandlerDispatcher implements ChannelHandler {
}
public ChannelHandlerDispatcher(Collection<ChannelHandler> handlers) {
if (handlers != null && !handlers.isEmpty()) {
if (CollectionUtils.isNotEmpty(handlers)) {
this.channelHandlers.addAll(handlers);
}
}

View File

@ -81,7 +81,7 @@ public class DeprecatedTelnetCodec implements Codec {
URL url = channel.getUrl();
if (url != null) {
String parameter = url.getParameter(Constants.CHARSET_KEY);
if (parameter != null && parameter.length() > 0) {
if (StringUtils.isNotEmpty(parameter)) {
try {
return Charset.forName(parameter);
} catch (Throwable t) {

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.NetUtils;
@ -106,7 +107,7 @@ public class NettyServer extends AbstractServer implements Server {
}
try {
Collection<org.apache.dubbo.remoting.Channel> channels = getChannels();
if (channels != null && !channels.isEmpty()) {
if (CollectionUtils.isNotEmpty(channels)) {
for (org.apache.dubbo.remoting.Channel channel : channels) {
try {
channel.close();

View File

@ -17,6 +17,8 @@
package org.apache.dubbo.remoting.transport.netty4.logging;
import org.apache.dubbo.common.utils.ArrayUtils;
/**
* Holds the results of formatting done by {@link MessageFormatter}.
*/
@ -43,7 +45,7 @@ class FormattingTuple {
}
static Object[] trimmedCopy(Object[] argArray) {
if (argArray == null || argArray.length == 0) {
if (ArrayUtils.isEmpty(argArray)) {
throw new IllegalStateException("non-sensical empty or null argument array");
}
final int trimmedLen = argArray.length - 1;

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.transport.netty4.logging;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import java.text.MessageFormat;
import java.util.HashMap;
@ -141,7 +142,7 @@ final class MessageFormatter {
}
static Throwable getThrowableCandidate(Object[] argArray) {
if (argArray == null || argArray.length == 0) {
if (ArrayUtils.isEmpty(argArray)) {
return null;
}

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.rpc;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
@ -605,7 +606,7 @@ public class RpcContext {
public RpcContext setInvokers(List<Invoker<?>> invokers) {
this.invokers = invokers;
if (invokers != null && !invokers.isEmpty()) {
if (CollectionUtils.isNotEmpty(invokers)) {
List<URL> urls = new ArrayList<URL>(invokers.size());
for (Invoker<?> invoker : invokers) {
urls.add(invoker.getUrl());

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
@ -140,7 +141,7 @@ public class AccessLogFilter implements Filter {
}
sn.append(") ");
Object[] args = inv.getArguments();
if (args != null && args.length > 0) {
if (ArrayUtils.isNotEmpty(args)) {
sn.append(JSON.toJSONString(args));
}
String msg = sn.toString();

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.listener;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Invoker;
@ -41,7 +42,7 @@ public class ListenerExporterWrapper<T> implements Exporter<T> {
}
this.exporter = exporter;
this.listeners = listeners;
if (listeners != null && !listeners.isEmpty()) {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (ExporterListener listener : listeners) {
if (listener != null) {
@ -69,7 +70,7 @@ public class ListenerExporterWrapper<T> implements Exporter<T> {
try {
exporter.unexport();
} finally {
if (listeners != null && !listeners.isEmpty()) {
if (CollectionUtils.isNotEmpty(listeners)) {
RuntimeException exception = null;
for (ExporterListener listener : listeners) {
if (listener != null) {

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.listener;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.InvokerListener;
@ -44,7 +45,7 @@ public class ListenerInvokerWrapper<T> implements Invoker<T> {
}
this.invoker = invoker;
this.listeners = listeners;
if (listeners != null && !listeners.isEmpty()) {
if (CollectionUtils.isNotEmpty(listeners)) {
for (InvokerListener listener : listeners) {
if (listener != null) {
try {
@ -87,7 +88,7 @@ public class ListenerInvokerWrapper<T> implements Invoker<T> {
try {
invoker.destroy();
} finally {
if (listeners != null && !listeners.isEmpty()) {
if (CollectionUtils.isNotEmpty(listeners)) {
for (InvokerListener listener : listeners) {
if (listener != null) {
try {

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
@ -75,7 +76,7 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
}
private static Map<String, String> convertAttachment(URL url, String[] keys) {
if (keys == null || keys.length == 0) {
if (ArrayUtils.isEmpty(keys)) {
return null;
}
Map<String, String> attachment = new HashMap<String, String>();

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.PojoUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProxyFactory;
@ -78,7 +79,7 @@ final public class MockInvoker<T> implements Invoker<T> {
} else {
value = mock;
}
if (returnTypes != null && returnTypes.length > 0) {
if (ArrayUtils.isNotEmpty(returnTypes)) {
value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
}
return value;

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.support;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
public class ProtocolUtils {
@ -31,7 +32,7 @@ public class ProtocolUtils {
public static String serviceKey(int port, String serviceName, String serviceVersion, String serviceGroup) {
StringBuilder buf = new StringBuilder();
if (serviceGroup != null && serviceGroup.length() > 0) {
if (StringUtils.isNotEmpty(serviceGroup)) {
buf.append(serviceGroup);
buf.append("/");
}

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.RpcInvocation;
@ -47,7 +48,7 @@ public class RpcUtils {
&& invocation.getInvoker().getUrl() != null
&& !invocation.getMethodName().startsWith("$")) {
String service = invocation.getInvoker().getUrl().getServiceInterface();
if (service != null && service.length() > 0) {
if (StringUtils.isNotEmpty(service)) {
Class<?> invokerInterface = invocation.getInvoker().getInterface();
Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service)
: ReflectUtils.forName(service);
@ -71,7 +72,7 @@ public class RpcUtils {
&& invocation.getInvoker().getUrl() != null
&& !invocation.getMethodName().startsWith("$")) {
String service = invocation.getInvoker().getUrl().getServiceInterface();
if (service != null && service.length() > 0) {
if (StringUtils.isNotEmpty(service)) {
Class<?> invokerInterface = invocation.getInvoker().getInterface();
Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service)
: ReflectUtils.forName(service);

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.rpc.Filter;
@ -85,7 +86,7 @@ public class TraceFilter implements Filter {
key = invoker.getInterface().getName();
channels = tracers.get(key);
}
if (channels != null && !channels.isEmpty()) {
if (CollectionUtils.isNotEmpty(channels)) {
for (Channel channel : new ArrayList<Channel>(channels)) {
if (channel.isConnected()) {
try {

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.protocol.http;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.http.HttpBinder;
import org.apache.dubbo.remoting.http.HttpHandler;
import org.apache.dubbo.remoting.http.HttpServer;
@ -132,7 +133,7 @@ public class HttpProtocol extends AbstractProxyProtocol {
httpProxyFactoryBean.setServiceUrl(key);
httpProxyFactoryBean.setServiceInterface(serviceType);
String client = url.getParameter(Constants.CLIENT_KEY);
if (client == null || client.length() == 0 || "simple".equals(client)) {
if (StringUtils.isEmpty(client) || "simple".equals(client)) {
SimpleHttpInvokerRequestExecutor httpInvokerRequestExecutor = new SimpleHttpInvokerRequestExecutor() {
@Override
protected void prepareConnection(HttpURLConnection con,

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.protocol.injvm;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
@ -56,7 +57,7 @@ public class InjvmProtocol extends AbstractProtocol implements Protocol {
if (!key.getServiceKey().contains("*")) {
result = map.get(key.getServiceKey());
} else {
if (map != null && !map.isEmpty()) {
if (CollectionUtils.isNotEmptyMap(map)) {
for (Exporter<?> exporter : map.values()) {
if (UrlUtils.isServiceKeyMatch(key, exporter.getInvoker().getUrl())) {
result = exporter;