Skip to content

Commit 9a20194

Browse files
committed
* Refactor: string checks with idiomatic alternatives
1 parent da872e5 commit 9a20194

File tree

10 files changed

+12
-14
lines changed

10 files changed

+12
-14
lines changed

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private ServiceDTO resolveConfigService() {
346346

347347
private List<ServiceDTO> getConfigServices() {
348348
List<ServiceDTO> services = m_serviceLocator.getConfigServices();
349-
if (services.size() == 0) {
349+
if (services.isEmpty()) {
350350
throw new ApolloConfigException("No available config service");
351351
}
352352

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public void run() {
379379

380380
private List<ServiceDTO> getConfigServices() {
381381
List<ServiceDTO> services = m_serviceLocator.getConfigServices();
382-
if (services.size() == 0) {
382+
if (services.isEmpty()) {
383383
throw new ApolloConfigException("No available config service");
384384
}
385385

apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private <T> HttpResponse<T> doGetWithSerializeFunction(HttpRequest httpRequest,
9797
conn.setRequestMethod("GET");
9898

9999
Map<String, String> headers = httpRequest.getHeaders();
100-
if (headers != null && headers.size() > 0) {
100+
if (headers != null && !headers.isEmpty()) {
101101
for (Map.Entry<String, String> entry : headers.entrySet()) {
102102
conn.setRequestProperty(entry.getKey(), entry.getValue());
103103
}

apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ private Yaml createYaml() {
7373
private boolean process(MatchCallback callback, Yaml yaml, String content) {
7474
int count = 0;
7575
if (logger.isDebugEnabled()) {
76-
logger.debug("Loading from YAML: " + content);
76+
logger.debug("Loading from YAML: {}", content);
7777
}
7878
for (Object object : yaml.loadAll(content)) {
7979
if (object != null && process(asMap(object), callback)) {
8080
count++;
8181
}
8282
}
8383
if (logger.isDebugEnabled()) {
84-
logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") + " from YAML resource: " + content);
84+
logger.debug("Loaded {} document{} from YAML resource: {}", count, count > 1 ? "s" : "", content);
8585
}
8686
return (count > 0);
8787
}
@@ -118,7 +118,7 @@ private boolean process(Map<String, Object> map, MatchCallback callback) {
118118
properties.putAll(getFlattenedMap(map));
119119

120120
if (logger.isDebugEnabled()) {
121-
logger.debug("Merging document (no matchers set): " + map);
121+
logger.debug("Merging document (no matchers set): {}", map);
122122
}
123123
callback.process(properties, map);
124124
return true;

apollo-core/src/main/java/com/ctrip/framework/apollo/core/MetaDomainConsts.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ public void run() {
222222
updateMetaServerAddresses(metaServerAddresses);
223223
}
224224
} catch (Throwable ex) {
225-
logger
226-
.warn(String.format("Refreshing meta server address failed, will retry in %d seconds",
227-
REFRESH_INTERVAL_IN_SECOND), ex);
225+
logger.warn("Refreshing meta server address failed, will retry in {} seconds", REFRESH_INTERVAL_IN_SECOND, ex);
228226
}
229227
}
230228
}, REFRESH_INTERVAL_IN_SECOND, REFRESH_INTERVAL_IN_SECOND, TimeUnit.SECONDS);

apollo-core/src/main/java/com/ctrip/framework/apollo/core/signature/Signature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static String url2PathWithQuery(String urlString) {
6060
String query = url.getQuery();
6161

6262
String pathWithQuery = path;
63-
if (query != null && query.length() > 0) {
63+
if (query != null && !query.isEmpty()) {
6464
pathWithQuery += "?" + query;
6565
}
6666
return pathWithQuery;

apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ApolloThreadFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean satisfy(Thread thread) {
6060
return !thread.isAlive() || thread.isInterrupted() || thread.isDaemon();
6161
}
6262
});
63-
if (alives.size() > 0) {
63+
if (!alives.isEmpty()) {
6464
log.info("Alive apollo threads: {}", alives);
6565
try {
6666
TimeUnit.SECONDS.sleep(2);

apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static Properties readConfigFile(String configPath, Properties defaults)
6565

6666
}
6767
if (sb.length() > 0) {
68-
logger.debug("Reading properties: \n" + sb);
68+
logger.debug("Reading properties: \n{}", sb);
6969
} else {
7070
logger.warn("No available properties: {}", configPath);
7171
}

apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class StringUtils {
4141
* @return <code>true</code> if the String is empty or null
4242
*/
4343
public static boolean isEmpty(String str) {
44-
return str == null || str.length() == 0;
44+
return str == null || str.isEmpty();
4545
}
4646

4747

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenPageDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public List<T> getContent() {
5353
}
5454

5555
public boolean hasContent() {
56-
return content != null && content.size() > 0;
56+
return content != null && !content.isEmpty();
5757
}
5858

5959
}

0 commit comments

Comments
 (0)