From 9588188800fd4d2f1f1dd15989e4e9bc999a6633 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 2 Mar 2020 20:36:46 +0100 Subject: [PATCH] Use isEmpty() where possible See gh-20370 --- .../boot/build/mavenplugin/PluginXmlParser.java | 6 +++--- .../boot/buildpack/platform/docker/TotalProgressBar.java | 2 +- .../boot/configurationprocessor/TypeUtils.java | 4 ++-- .../springframework/boot/jarmode/layertools/Context.java | 2 +- .../org/springframework/boot/ansi/AnsiPropertySource.java | 4 ++-- .../smoketest/integration/producer/ProducerApplication.java | 4 ++-- .../java/smoketest/parent/producer/ProducerApplication.java | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/PluginXmlParser.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/PluginXmlParser.java index fddd516374e..35e163b82d7 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/PluginXmlParser.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/PluginXmlParser.java @@ -60,7 +60,7 @@ class PluginXmlParser { private String textAt(String path, Node source) throws XPathExpressionException { String text = this.xpath.evaluate(path + "/text()", source); - return (text.length() == 0) ? null : text; + return text.isEmpty() ? null : text; } private List parseMojos(Node plugin) throws XPathExpressionException { @@ -81,12 +81,12 @@ class PluginXmlParser { Map userProperties = new HashMap<>(); for (Node parameterConfigurationNode : nodesAt("configuration/*", mojoNode)) { String userProperty = parameterConfigurationNode.getTextContent(); - if (userProperty != null && userProperty.length() > 0) { + if (userProperty != null && !userProperty.isEmpty()) { userProperties.put(parameterConfigurationNode.getNodeName(), userProperty.replace("${", "`").replace("}", "`")); } Node defaultValueAttribute = parameterConfigurationNode.getAttributes().getNamedItem("default-value"); - if (defaultValueAttribute != null && defaultValueAttribute.getTextContent().length() > 0) { + if (defaultValueAttribute != null && !defaultValueAttribute.getTextContent().isEmpty()) { defaultValues.put(parameterConfigurationNode.getNodeName(), defaultValueAttribute.getTextContent()); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/TotalProgressBar.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/TotalProgressBar.java index 6d828437b82..b478efd33d4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/TotalProgressBar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/TotalProgressBar.java @@ -63,7 +63,7 @@ public class TotalProgressBar implements Consumer { public TotalProgressBar(String prefix, char progressChar, boolean bookend, PrintStream out) { this.progressChar = progressChar; this.bookend = bookend; - if (prefix != null && prefix.length() > 0) { + if (prefix != null && !prefix.isEmpty()) { out.print(prefix); out.print(" "); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java index 21039f7af15..844c5c460a0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -154,7 +154,7 @@ class TypeUtils { if (((TypeElement) this.types.asElement(type)).getQualifiedName().contentEquals(Collection.class.getName())) { DeclaredType declaredType = (DeclaredType) type; // raw type, just "Collection" - if (declaredType.getTypeArguments().size() == 0) { + if (declaredType.getTypeArguments().isEmpty()) { return this.types.getDeclaredType(this.env.getElementUtils().getTypeElement(Object.class.getName())); } // return type argument to Collection<...> diff --git a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/Context.java b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/Context.java index 9b6edf3b455..d072d120aa9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/Context.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/Context.java @@ -62,7 +62,7 @@ class Context { return null; } String relativePath = sourcePath.substring(workingPath.length() + 1); - return (relativePath.length() > 0) ? relativePath : null; + return !relativePath.isEmpty() ? relativePath : null; } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java index 4c0cce7d180..1553ead56d5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -162,7 +162,7 @@ public class AnsiPropertySource extends PropertySource { return false; } } - return postfix.length() > 0; + return !postfix.isEmpty(); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java index 3dc4a689c23..162f9075ec9 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public class ProducerApplication implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { this.serviceProperties.getInputDir().mkdirs(); - if (args.getNonOptionArgs().size() > 0) { + if (!args.getNonOptionArgs().isEmpty()) { FileOutputStream stream = new FileOutputStream( new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); for (String arg : args.getNonOptionArgs()) { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java index 7cee22afb62..f33e25bedbc 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public class ProducerApplication implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { this.serviceProperties.getInputDir().mkdirs(); - if (args.getNonOptionArgs().size() > 0) { + if (!args.getNonOptionArgs().isEmpty()) { FileOutputStream stream = new FileOutputStream( new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); for (String arg : args.getNonOptionArgs()) {