Skip to content

Commit 458a450

Browse files
CrazyHZMbeiwei30
authored andcommitted
call the util method (#3230)
* Code optimization, call the util method * mofidy * modify * * import package
1 parent 416c575 commit 458a450

File tree

72 files changed

+306
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+306
-233
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static String toParameterString(ConfigItem item) {
130130
sb.append(item.getSide());
131131
}
132132
Map<String, String> parameters = item.getParameters();
133-
if (parameters == null || parameters.isEmpty()) {
133+
if (CollectionUtils.isEmptyMap(parameters)) {
134134
throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " +
135135
"you want to change in the rule.");
136136
}

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.dubbo.common.URL;
2020
import org.apache.dubbo.common.logger.Logger;
2121
import org.apache.dubbo.common.logger.LoggerFactory;
22+
import org.apache.dubbo.common.utils.CollectionUtils;
2223
import org.apache.dubbo.rpc.Invocation;
2324
import org.apache.dubbo.rpc.Invoker;
2425
import org.apache.dubbo.rpc.RpcException;
@@ -48,8 +49,8 @@ public StaticDirectory(URL url, List<Invoker<T>> invokers) {
4849
}
4950

5051
public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) {
51-
super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain);
52-
if (invokers == null || invokers.isEmpty()) {
52+
super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain);
53+
if (CollectionUtils.isEmpty(invokers)) {
5354
throw new IllegalArgumentException("invokers == null");
5455
}
5556
this.invokers = invokers;

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.dubbo.common.Constants;
2020
import org.apache.dubbo.common.URL;
21+
import org.apache.dubbo.common.utils.CollectionUtils;
2122
import org.apache.dubbo.rpc.Invocation;
2223
import org.apache.dubbo.rpc.Invoker;
2324
import org.apache.dubbo.rpc.cluster.LoadBalance;
@@ -44,7 +45,7 @@ static int calculateWarmupWeight(int uptime, int warmup, int weight) {
4445

4546
@Override
4647
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) {
47-
if (invokers == null || invokers.isEmpty()) {
48+
if (CollectionUtils.isEmpty(invokers)) {
4849
return null;
4950
}
5051
if (invokers.size() == 1) {

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.common.logger.Logger;
2222
import org.apache.dubbo.common.logger.LoggerFactory;
23+
import org.apache.dubbo.common.utils.CollectionUtils;
2324
import org.apache.dubbo.common.utils.NetUtils;
2425
import org.apache.dubbo.common.utils.StringUtils;
2526
import org.apache.dubbo.common.utils.UrlUtils;
@@ -101,7 +102,7 @@ private static Map<String, MatchPair> parseRule(String rule)
101102
String separator = matcher.group(1);
102103
String content = matcher.group(2);
103104
// Start part of the condition expression.
104-
if (separator == null || separator.length() == 0) {
105+
if (StringUtils.isEmpty(separator)) {
105106
pair = new MatchPair();
106107
condition.put(content, pair);
107108
}
@@ -163,7 +164,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
163164
return invokers;
164165
}
165166

166-
if (invokers == null || invokers.isEmpty()) {
167+
if (CollectionUtils.isEmpty(invokers)) {
167168
return invokers;
168169
}
169170
try {
@@ -205,11 +206,11 @@ public URL getUrl() {
205206
}
206207

207208
boolean matchWhen(URL url, Invocation invocation) {
208-
return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation);
209+
return CollectionUtils.isEmptyMap(whenCondition) || matchCondition(whenCondition, url, null, invocation);
209210
}
210211

211212
private boolean matchThen(URL url, URL param) {
212-
return !(thenCondition == null || thenCondition.isEmpty()) && matchCondition(thenCondition, url, param, null);
213+
return CollectionUtils.isNotEmptyMap(thenCondition) && matchCondition(thenCondition, url, param, null);
213214
}
214215

215216
private boolean matchCondition(Map<String, MatchPair> condition, URL url, URL param, Invocation invocation) {

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.common.logger.Logger;
2222
import org.apache.dubbo.common.logger.LoggerFactory;
23+
import org.apache.dubbo.common.utils.StringUtils;
2324
import org.apache.dubbo.rpc.Invocation;
2425
import org.apache.dubbo.rpc.Invoker;
2526
import org.apache.dubbo.rpc.RpcContext;
@@ -58,10 +59,10 @@ public ScriptRouter(URL url) {
5859
String type = url.getParameter(Constants.TYPE_KEY);
5960
this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
6061
String rule = url.getParameterAndDecoded(Constants.RULE_KEY);
61-
if (type == null || type.length() == 0) {
62+
if (StringUtils.isEmpty(type)) {
6263
type = Constants.DEFAULT_SCRIPT_TYPE_KEY;
6364
}
64-
if (rule == null || rule.length() == 0) {
65+
if (StringUtils.isEmpty(rule)) {
6566
throw new IllegalStateException("route rule can not be empty. rule:" + rule);
6667
}
6768
ScriptEngine engine = engines.get(type);

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void setApplication(String app) {
181181

182182
@Override
183183
public <T> void notify(List<Invoker<T>> invokers) {
184-
if (invokers == null || invokers.isEmpty()) {
184+
if (CollectionUtils.isEmpty(invokers)) {
185185
return;
186186
}
187187

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.common.logger.Logger;
2222
import org.apache.dubbo.common.logger.LoggerFactory;
23+
import org.apache.dubbo.common.utils.CollectionUtils;
2324
import org.apache.dubbo.common.utils.StringUtils;
2425
import org.apache.dubbo.rpc.Invocation;
2526
import org.apache.dubbo.rpc.Invoker;
@@ -103,7 +104,7 @@ private Result doMockInvoke(Invocation invocation, RpcException e) {
103104
Invoker<T> minvoker;
104105

105106
List<Invoker<T>> mockInvokers = selectMockInvoker(invocation);
106-
if (mockInvokers == null || mockInvokers.isEmpty()) {
107+
if (CollectionUtils.isEmpty(mockInvokers)) {
107108
minvoker = (Invoker<T>) new MockInvoker(directory.getUrl());
108109
} else {
109110
minvoker = mockInvokers.get(0);

dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,37 +96,37 @@ public String getDecodedParameter(String key, String defaultValue) {
9696

9797
public String getParameter(String key) {
9898
String value = parameters.get(key);
99-
if (value == null || value.length() == 0) {
99+
if (StringUtils.isEmpty(value)) {
100100
value = parameters.get(Constants.HIDE_KEY_PREFIX + key);
101101
}
102-
if (value == null || value.length() == 0) {
102+
if (StringUtils.isEmpty(value)) {
103103
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
104104
}
105-
if (value == null || value.length() == 0) {
105+
if (StringUtils.isEmpty(value)) {
106106
value = parameters.get(Constants.HIDE_KEY_PREFIX + Constants.DEFAULT_KEY_PREFIX + key);
107107
}
108108
return value;
109109
}
110110

111111
public String getParameter(String key, String defaultValue) {
112112
String value = getParameter(key);
113-
if (value == null || value.length() == 0) {
113+
if (StringUtils.isEmpty(value)) {
114114
return defaultValue;
115115
}
116116
return value;
117117
}
118118

119119
public int getIntParameter(String key) {
120120
String value = getParameter(key);
121-
if (value == null || value.length() == 0) {
121+
if (StringUtils.isEmpty(value)) {
122122
return 0;
123123
}
124124
return Integer.parseInt(value);
125125
}
126126

127127
public int getIntParameter(String key, int defaultValue) {
128128
String value = getParameter(key);
129-
if (value == null || value.length() == 0) {
129+
if (StringUtils.isEmpty(value)) {
130130
return defaultValue;
131131
}
132132
return Integer.parseInt(value);
@@ -137,7 +137,7 @@ public int getPositiveIntParameter(String key, int defaultValue) {
137137
throw new IllegalArgumentException("defaultValue <= 0");
138138
}
139139
String value = getParameter(key);
140-
if (value == null || value.length() == 0) {
140+
if (StringUtils.isEmpty(value)) {
141141
return defaultValue;
142142
}
143143
int i = Integer.parseInt(value);
@@ -149,15 +149,15 @@ public int getPositiveIntParameter(String key, int defaultValue) {
149149

150150
public boolean getBooleanParameter(String key) {
151151
String value = getParameter(key);
152-
if (value == null || value.length() == 0) {
152+
if (StringUtils.isEmpty(value)) {
153153
return false;
154154
}
155155
return Boolean.parseBoolean(value);
156156
}
157157

158158
public boolean getBooleanParameter(String key, boolean defaultValue) {
159159
String value = getParameter(key);
160-
if (value == null || value.length() == 0) {
160+
if (StringUtils.isEmpty(value)) {
161161
return defaultValue;
162162
}
163163
return Boolean.parseBoolean(value);
@@ -170,34 +170,34 @@ public boolean hasParamter(String key) {
170170

171171
public String getMethodParameter(String method, String key) {
172172
String value = parameters.get(method + "." + key);
173-
if (value == null || value.length() == 0) {
173+
if (StringUtils.isEmpty(value)) {
174174
value = parameters.get(Constants.HIDE_KEY_PREFIX + method + "." + key);
175175
}
176-
if (value == null || value.length() == 0) {
176+
if (StringUtils.isEmpty(value)) {
177177
return getParameter(key);
178178
}
179179
return value;
180180
}
181181

182182
public String getMethodParameter(String method, String key, String defaultValue) {
183183
String value = getMethodParameter(method, key);
184-
if (value == null || value.length() == 0) {
184+
if (StringUtils.isEmpty(value)) {
185185
return defaultValue;
186186
}
187187
return value;
188188
}
189189

190190
public int getMethodIntParameter(String method, String key) {
191191
String value = getMethodParameter(method, key);
192-
if (value == null || value.length() == 0) {
192+
if (StringUtils.isEmpty(value)) {
193193
return 0;
194194
}
195195
return Integer.parseInt(value);
196196
}
197197

198198
public int getMethodIntParameter(String method, String key, int defaultValue) {
199199
String value = getMethodParameter(method, key);
200-
if (value == null || value.length() == 0) {
200+
if (StringUtils.isEmpty(value)) {
201201
return defaultValue;
202202
}
203203
return Integer.parseInt(value);
@@ -208,7 +208,7 @@ public int getMethodPositiveIntParameter(String method, String key, int defaultV
208208
throw new IllegalArgumentException("defaultValue <= 0");
209209
}
210210
String value = getMethodParameter(method, key);
211-
if (value == null || value.length() == 0) {
211+
if (StringUtils.isEmpty(value)) {
212212
return defaultValue;
213213
}
214214
int i = Integer.parseInt(value);
@@ -220,15 +220,15 @@ public int getMethodPositiveIntParameter(String method, String key, int defaultV
220220

221221
public boolean getMethodBooleanParameter(String method, String key) {
222222
String value = getMethodParameter(method, key);
223-
if (value == null || value.length() == 0) {
223+
if (StringUtils.isEmpty(value)) {
224224
return false;
225225
}
226226
return Boolean.parseBoolean(value);
227227
}
228228

229229
public boolean getMethodBooleanParameter(String method, String key, boolean defaultValue) {
230230
String value = getMethodParameter(method, key);
231-
if (value == null || value.length() == 0) {
231+
if (StringUtils.isEmpty(value)) {
232232
return defaultValue;
233233
}
234234
return Boolean.parseBoolean(value);

0 commit comments

Comments
 (0)