From 32f9e90de578381dc025da40ad9b1f4943e5cd15 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 25 Jan 2017 09:50:31 +0900 Subject: [PATCH] Replace 'String.length() == 0' with 'String.isEmpty()' See gh-8103 --- .../endpoint/ConfigurationPropertiesReportEndpoint.java | 2 +- .../boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java | 2 +- .../boot/autoconfigure/amqp/RabbitProperties.java | 2 +- .../boot/autoconfigure/h2/H2ConsoleProperties.java | 2 +- .../boot/autoconfigure/webservices/WebServicesProperties.java | 2 +- .../java/org/springframework/boot/loader/jar/AsciiBytes.java | 2 +- .../org/springframework/boot/loader/jar/JarURLConnection.java | 4 ++-- .../springframework/boot/bind/RelaxedConversionService.java | 2 +- .../ConfigurationWarningsApplicationContextInitializer.java | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java index 958bfcce5f..7491cfe416 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java @@ -234,7 +234,7 @@ public class ConfigurationPropertiesReportEndpoint private Map sanitize(String prefix, Map map) { for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); - String qualifiedKey = (prefix.length() == 0 ? prefix : prefix + ".") + key; + String qualifiedKey = (prefix.isEmpty() ? prefix : prefix + ".") + key; Object value = entry.getValue(); if (value instanceof Map) { map.put(key, sanitize(qualifiedKey, (Map) value)); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java index 110445c843..dfee586dee 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/AbstractMvcEndpoint.java @@ -69,7 +69,7 @@ public abstract class AbstractMvcEndpoint extends WebMvcConfigurerAdapter @PostConstruct private void validate() { Assert.notNull(this.path, "Path must not be null"); - Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + Assert.isTrue(this.path.isEmpty() || this.path.startsWith("/"), "Path must start with / or be empty"); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 929b6afadb..c4bdc5d582 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -770,7 +770,7 @@ public class RabbitProperties { int hostIndex = input.indexOf("/"); if (hostIndex >= 0) { this.virtualHost = input.substring(hostIndex + 1); - if (this.virtualHost.length() == 0) { + if (this.virtualHost.isEmpty()) { this.virtualHost = "/"; } input = input.substring(0, hostIndex); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java index 6bc37a86cc..dcc931e593 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java @@ -47,7 +47,7 @@ public class H2ConsoleProperties { @PostConstruct private void validate() { Assert.notNull(this.path, "Path must not be null"); - Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + Assert.isTrue(this.path.isEmpty() || this.path.startsWith("/"), "Path must start with / or be empty"); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java index 3d6d73a188..87a57a2cfa 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesProperties.java @@ -44,7 +44,7 @@ public class WebServicesProperties { @PostConstruct private void validate() { Assert.notNull(this.path, "Path must not be null"); - Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"), + Assert.isTrue(this.path.isEmpty() || this.path.startsWith("/"), "Path must start with / or be empty"); } diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java index 333d7775f3..d6b2ab42b2 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java @@ -121,7 +121,7 @@ final class AsciiBytes { } public AsciiBytes append(String string) { - if (string == null || string.length() == 0) { + if (string == null || string.isEmpty()) { return this; } return append(string.getBytes(UTF_8)); diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 7f2b5ce6ed..589e5b23ff 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -293,7 +293,7 @@ final class JarURLConnection extends java.net.JarURLConnection { } private String decode(String source) { - if (source.length() == 0 || (source.indexOf('%') < 0)) { + if (source.isEmpty() || (source.indexOf('%') < 0)) { return source; } ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length()); @@ -347,7 +347,7 @@ final class JarURLConnection extends java.net.JarURLConnection { } public boolean isEmpty() { - return this.name.length() == 0; + return this.name.isEmpty(); } public String getContentType() { diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java index affdec0d1e..67c511ae5b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java @@ -120,7 +120,7 @@ class RelaxedConversionService implements ConversionService { @Override public T convert(String source) { - if (source.length() == 0) { + if (source.isEmpty()) { // It's an empty enum identifier: reset the enum value to null. return null; } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializer.java b/spring-boot/src/main/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializer.java index bc61b1f561..aa7ba3de1a 100755 --- a/spring-boot/src/main/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializer.java @@ -206,14 +206,14 @@ public class ConfigurationWarningsApplicationContextInitializer } private boolean isProblematicPackage(String scannedPackage) { - if (scannedPackage == null || scannedPackage.length() == 0) { + if (scannedPackage == null || scannedPackage.isEmpty()) { return true; } return PROBLEM_PACKAGES.contains(scannedPackage); } private String getDisplayName(String scannedPackage) { - if (scannedPackage == null || scannedPackage.length() == 0) { + if (scannedPackage == null || scannedPackage.isEmpty()) { return "the default package"; } return "'" + scannedPackage + "'";