Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CollectionUtils.isEmpty() and StringUtils.hasLength() #40645

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.springframework.boot.actuate.endpoint.Show;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.CollectionUtils;

/**
* Properties used to configure the health endpoint and endpoint groups.
Expand Down Expand Up @@ -92,7 +93,7 @@ public List<String> getOrder() {
}

public void setOrder(List<String> statusOrder) {
if (statusOrder != null && !statusOrder.isEmpty()) {
if (!CollectionUtils.isEmpty(statusOrder)) {
this.order = statusOrder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -388,7 +389,7 @@ public ConditionMessage items(Style style, Collection<?> items) {
else if (StringUtils.hasLength(this.plural)) {
message.append(" ").append(this.plural);
}
if (items != null && !items.isEmpty()) {
if (!CollectionUtils.isEmpty(items)) {
message.append(" ").append(StringUtils.collectionToDelimitedString(items, ", "));
}
return this.condition.because(message.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.buildpack.platform.build;

import org.springframework.util.StringUtils;

/**
* Exception thrown to indicate a Builder error.
*
Expand Down Expand Up @@ -52,7 +54,7 @@ public int getStatusCode() {

private static String buildMessage(String operation, int statusCode) {
StringBuilder message = new StringBuilder("Builder");
if (operation != null && !operation.isEmpty()) {
if (StringUtils.hasLength(operation)) {
message.append(" lifecycle '").append(operation).append("'");
}
message.append(" failed with status code ").append(statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.boot.buildpack.platform.docker.type.Layer;
import org.springframework.boot.buildpack.platform.io.Content;
import org.springframework.boot.buildpack.platform.io.Owner;
import org.springframework.util.CollectionUtils;

/**
* A short-lived builder that is created for each {@link Lifecycle} run.
Expand Down Expand Up @@ -66,7 +67,7 @@ class EphemeralBuilder {
update.withUpdatedConfig(this.builderMetadata::attachTo);
update.withUpdatedConfig((config) -> config.withLabel(BUILDER_FOR_LABEL_NAME, targetImage.toString()));
update.withTag(name);
if (env != null && !env.isEmpty()) {
if (!CollectionUtils.isEmpty(env)) {
update.withNewLayer(getEnvLayer(env));
}
if (buildpacks != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.PrintStream;
import java.util.function.Consumer;

import org.springframework.util.StringUtils;

/**
* Utility to render a simple progress bar based on consumed {@link TotalProgressEvent}
* objects.
Expand Down Expand Up @@ -63,7 +65,7 @@ public TotalProgressBar(String prefix, PrintStream out) {
public TotalProgressBar(String prefix, char progressChar, boolean bookend, PrintStream out) {
this.progressChar = progressChar;
this.bookend = bookend;
if (prefix != null && !prefix.isEmpty()) {
if (StringUtils.hasLength(prefix)) {
out.print(prefix);
out.print(" ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -71,7 +72,7 @@ public class ContainerConfig {
}
ArrayNode bindsNode = hostConfigNode.putArray("Binds");
bindings.forEach((binding) -> bindsNode.add(binding.toString()));
if (securityOptions != null && !securityOptions.isEmpty()) {
if (!CollectionUtils.isEmpty(securityOptions)) {
ArrayNode securityOptsNode = hostConfigNode.putArray("SecurityOpt");
securityOptions.forEach(securityOptsNode::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
import org.springframework.boot.buildpack.platform.io.ZipFileTarArchive;
import org.springframework.boot.gradle.util.VersionExtractor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -382,7 +383,7 @@ private BuildRequest customizeRunImage(BuildRequest request) {

private BuildRequest customizeEnvironment(BuildRequest request) {
Map<String, String> environment = getEnvironment().getOrNull();
if (environment != null && !environment.isEmpty()) {
if (!CollectionUtils.isEmpty(environment)) {
request = request.withEnv(environment);
}
return request;
Expand Down Expand Up @@ -411,23 +412,23 @@ private BuildRequest customizePublish(BuildRequest request) {

private BuildRequest customizeBuildpacks(BuildRequest request) {
List<String> buildpacks = getBuildpacks().getOrNull();
if (buildpacks != null && !buildpacks.isEmpty()) {
if (!CollectionUtils.isEmpty(buildpacks)) {
return request.withBuildpacks(buildpacks.stream().map(BuildpackReference::of).toList());
}
return request;
}

private BuildRequest customizeBindings(BuildRequest request) {
List<String> bindings = getBindings().getOrNull();
if (bindings != null && !bindings.isEmpty()) {
if (!CollectionUtils.isEmpty(bindings)) {
return request.withBindings(bindings.stream().map(Binding::of).toList());
}
return request;
}

private BuildRequest customizeTags(BuildRequest request) {
List<String> tags = getTags().getOrNull();
if (tags != null && !tags.isEmpty()) {
if (!CollectionUtils.isEmpty(tags)) {
return request.withTags(tags.stream().map(ImageReference::of).toList());
}
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;

import org.springframework.util.StringUtils;

/**
* Encapsulates the configuration of the launch script for an executable jar or war.
*
Expand Down Expand Up @@ -111,7 +113,7 @@ private String augmentLineBreaks(String string) {
private void putIfMissing(Map<String, String> properties, String key, String... valueCandidates) {
if (!properties.containsKey(key)) {
for (String candidate : valueCandidates) {
if (candidate != null && !candidate.isEmpty()) {
if (StringUtils.hasLength(candidate)) {
properties.put(key, candidate);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.boot.loader.tools.Libraries;
import org.springframework.boot.loader.tools.LoaderImplementation;
import org.springframework.boot.loader.tools.Repackager;
import org.springframework.util.StringUtils;

/**
* Repackage existing JAR and WAR archives so that they can be executed from the command
Expand Down Expand Up @@ -271,7 +272,7 @@ private String removeLineBreaks(String description) {
private void putIfMissing(Properties properties, String key, String... valueCandidates) {
if (!properties.containsKey(key)) {
for (String candidate : valueCandidates) {
if (candidate != null && !candidate.isEmpty()) {
if (StringUtils.hasLength(candidate)) {
properties.put(key, candidate);
return;
}
Expand Down