Polish empty string checks

See gh-23550
This commit is contained in:
Santhoshkumar. P 2020-10-01 08:21:49 +05:30 committed by Stephane Nicoll
parent 294af45bb3
commit 5cb07e292d
8 changed files with 11 additions and 10 deletions

View File

@ -290,7 +290,7 @@ public class RabbitProperties {
}
public void setVirtualHost(String virtualHost) {
this.virtualHost = "".equals(virtualHost) ? "/" : virtualHost;
this.virtualHost = StringUtils.hasLength(virtualHost) ? virtualHost : "/";
}
public AddressShuffleMode getAddressShuffleMode() {

View File

@ -33,6 +33,7 @@ import jline.console.completer.StringsCompleter;
import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.options.OptionHelp;
import org.springframework.boot.cli.util.Log;
import org.springframework.util.StringUtils;
/**
* JLine {@link Completer} for Spring Boot {@link Command}s.
@ -74,7 +75,7 @@ public class CommandCompleter extends StringsCompleter {
int completionIndex = super.complete(buffer, cursor, candidates);
int spaceIndex = buffer.indexOf(' ');
String commandName = ((spaceIndex != -1) ? buffer.substring(0, spaceIndex) : "");
if (!"".equals(commandName.trim())) {
if (StringUtils.hasText(commandName)) {
for (Command command : this.commands) {
if (command.getName().equals(commandName)) {
if (cursor == buffer.length() && buffer.endsWith(" ")) {

View File

@ -298,7 +298,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private void processEndpoint(AnnotationMirror annotation, TypeElement element) {
Map<String, Object> elementValues = this.metadataEnv.getAnnotationElementValues(annotation);
String endpointId = (String) elementValues.get("id");
if (endpointId == null || "".equals(endpointId)) {
if (endpointId == null || endpointId.isEmpty()) {
return; // Can't process that endpoint
}
String endpointKey = ItemMetadata.newItemMetadataPrefix("management.endpoint.", endpointId);

View File

@ -180,8 +180,8 @@ class MetadataGenerationEnvironment {
reason = (String) elementValues.get("reason");
replacement = (String) elementValues.get("replacement");
}
reason = "".equals(reason) ? null : reason;
replacement = "".equals(replacement) ? null : replacement;
reason = (reason == null || reason.isEmpty()) ? null : reason;
replacement = (replacement == null || replacement.isEmpty()) ? null : replacement;
return new ItemDeprecation(reason, replacement);
}

View File

@ -180,7 +180,7 @@ class TypeUtils {
if (javadoc != null) {
javadoc = NEW_LINE_PATTERN.matcher(javadoc).replaceAll("").trim();
}
return "".equals(javadoc) ? null : javadoc;
return (javadoc == null || javadoc.isEmpty()) ? null : javadoc;
}
/**

View File

@ -171,7 +171,7 @@ public class ConfigurationMetadata {
public static String nestedPrefix(String prefix, String name) {
String nestedPrefix = (prefix != null) ? prefix : "";
String dashedName = toDashedCase(name);
nestedPrefix += "".equals(nestedPrefix) ? dashedName : "." + dashedName;
nestedPrefix += (nestedPrefix == null || nestedPrefix.isEmpty()) ? dashedName : "." + dashedName;
return nestedPrefix;
}

View File

@ -316,7 +316,7 @@ public class PropertiesLauncher extends Launcher {
for (String path : commaSeparatedPaths.split(",")) {
path = cleanupPath(path);
// "" means the user wants root of archive but not current directory
path = "".equals(path) ? "/" : path;
path = (path == null || path.isEmpty()) ? "/" : path;
paths.add(path);
}
if (paths.isEmpty()) {
@ -631,7 +631,7 @@ public class PropertiesLauncher extends Launcher {
}
EntryFilter filter = new PrefixMatchingArchiveFilter(root);
List<Archive> archives = asList(parent.getNestedArchives(null, filter));
if (("".equals(root) || ".".equals(root)) && !path.endsWith(".jar")
if ((root == null || root.isEmpty() || ".".equals(root)) && !path.endsWith(".jar")
&& parent != PropertiesLauncher.this.parent) {
// You can't find the root with an entry filter so it has to be added
// explicitly. But don't add the root of the parent archive.

View File

@ -413,7 +413,7 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
public static void registerUrlProtocolHandler() {
String handlers = System.getProperty(PROTOCOL_HANDLER, "");
System.setProperty(PROTOCOL_HANDLER,
("".equals(handlers) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE));
((handlers == null || handlers.isEmpty()) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE));
resetCachedUrlHandlers();
}