Fix checkstyle ternary issues

Fix checkstyle issues with ternary expressions following the
spring-javaformat upgrade.

See gh-13932
This commit is contained in:
Phillip Webb
2018-07-27 22:54:20 +01:00
parent ec1100a896
commit 7fc455654a
293 changed files with 714 additions and 685 deletions

View File

@@ -64,7 +64,7 @@ public class SpringApplicationWebApplicationInitializer
private Manifest getManifest(ServletContext servletContext) throws IOException {
InputStream stream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
return (stream != null ? new Manifest(stream) : null);
return (stream != null) ? new Manifest(stream) : null;
}
@Override

View File

@@ -171,7 +171,7 @@ public class CommandRunner implements Iterable<Command> {
ExitStatus result = run(argsWithoutDebugFlags);
// The caller will hang up if it gets a non-zero status
if (result != null && result.isHangup()) {
return (result.getCode() > 0 ? result.getCode() : 0);
return (result.getCode() > 0) ? result.getCode() : 0;
}
return 0;
}
@@ -260,7 +260,7 @@ public class CommandRunner implements Iterable<Command> {
}
protected boolean errorMessage(String message) {
Log.error(message != null ? message : "Unexpected error");
Log.error((message != null) ? message : "Unexpected error");
return message != null;
}
@@ -280,8 +280,8 @@ public class CommandRunner implements Iterable<Command> {
String usageHelp = command.getUsageHelp();
String description = command.getDescription();
Log.info(String.format("%n %1$s %2$-15s%n %3$s", command.getName(),
(usageHelp != null ? usageHelp : ""),
(description != null ? description : "")));
(usageHelp != null) ? usageHelp : "",
(description != null) ? description : ""));
}
}
Log.info("");

View File

@@ -230,7 +230,7 @@ abstract class ArchiveCommand extends OptionParsingCommand {
private String commaDelimitedClassNames(Class<?>[] classes) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < classes.length; i++) {
builder.append(i != 0 ? "," : "");
builder.append((i != 0) ? "," : "");
builder.append(classes[i].getName());
}
return builder.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -107,7 +107,7 @@ public class HelpCommand extends AbstractCommand {
}
Collection<HelpExample> examples = command.getExamples();
if (examples != null) {
Log.info(examples.size() != 1 ? "examples:" : "example:");
Log.info((examples.size() != 1) ? "examples:" : "example:");
Log.info("");
for (HelpExample example : examples) {
Log.info(" " + example.getDescription() + ":");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -45,7 +45,7 @@ public class HintCommand extends AbstractCommand {
@Override
public ExitStatus run(String... args) throws Exception {
try {
int index = (args.length != 0 ? Integer.valueOf(args[0]) - 1 : 0);
int index = (args.length != 0) ? Integer.valueOf(args[0]) - 1 : 0;
List<String> arguments = new ArrayList<>(args.length);
for (int i = 2; i < args.length; i++) {
arguments.add(args[i]);

View File

@@ -240,7 +240,7 @@ class InitializrService {
private String getContent(HttpEntity entity) throws IOException {
ContentType contentType = ContentType.getOrDefault(entity);
Charset charset = contentType.getCharset();
charset = (charset != null ? charset : StandardCharsets.UTF_8);
charset = (charset != null) ? charset : StandardCharsets.UTF_8;
byte[] content = FileCopyUtils.copyToByteArray(entity.getContent());
return new String(content, charset);
}

View File

@@ -416,7 +416,7 @@ class ProjectGenerationRequest {
}
if (this.output != null) {
int i = this.output.lastIndexOf('.');
return (i != -1 ? this.output.substring(0, i) : this.output);
return (i != -1) ? this.output.substring(0, i) : this.output;
}
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -45,8 +45,8 @@ class ProjectGenerator {
public void generateProject(ProjectGenerationRequest request, boolean force)
throws IOException {
ProjectGenerationResponse response = this.initializrService.generate(request);
String fileName = (request.getOutput() != null ? request.getOutput()
: response.getFileName());
String fileName = (request.getOutput() != null) ? request.getOutput()
: response.getFileName();
if (shouldExtract(request, response)) {
if (isZipArchive(response)) {
extractProject(response, request.getOutput(), force);
@@ -100,8 +100,8 @@ class ProjectGenerator {
private void extractProject(ProjectGenerationResponse entity, String output,
boolean overwrite) throws IOException {
File outputFolder = (output != null ? new File(output)
: new File(System.getProperty("user.dir")));
File outputFolder = (output != null) ? new File(output)
: new File(System.getProperty("user.dir"));
if (!outputFolder.exists()) {
outputFolder.mkdirs();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -59,7 +59,7 @@ public class InstallCommand extends OptionParsingCommand {
}
catch (Exception ex) {
String message = ex.getMessage();
Log.error(message != null ? message : ex.getClass().toString());
Log.error((message != null) ? message : ex.getClass().toString());
}
return ExitStatus.OK;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -75,7 +75,7 @@ public class UninstallCommand extends OptionParsingCommand {
}
catch (Exception ex) {
String message = ex.getMessage();
Log.error(message != null ? message : ex.getClass().toString());
Log.error((message != null) ? message : ex.getClass().toString());
}
return ExitStatus.OK;
}

View File

@@ -157,7 +157,8 @@ public class OptionHandler {
OptionHelpAdapter(OptionDescriptor descriptor) {
this.options = new LinkedHashSet<>();
for (String option : descriptor.options()) {
this.options.add((option.length() != 1 ? "--" : "-") + option);
String prefix = (option.length() != 1) ? "--" : "-";
this.options.add(prefix + option);
}
if (this.options.contains("--cp")) {
this.options.remove("--cp");

View File

@@ -130,7 +130,7 @@ public class SourceOptions {
}
private String asString(Object arg) {
return (arg != null ? String.valueOf(arg) : null);
return (arg != null) ? String.valueOf(arg) : null;
}
public List<String> getSources() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -129,7 +129,7 @@ public class CommandCompleter extends StringsCompleter {
OptionHelpLine(OptionHelp optionHelp) {
StringBuilder options = new StringBuilder();
for (String option : optionHelp.getOptions()) {
options.append(options.length() != 0 ? ", " : "");
options.append((options.length() != 0) ? ", " : "");
options.append(option);
}
this.options = options.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -140,7 +140,7 @@ public class Shell {
private void printBanner() {
String version = getClass().getPackage().getImplementationVersion();
version = (version != null ? " (v" + version + ")" : "");
version = (version != null) ? " (v" + version + ")" : "";
System.out.println(ansi("Spring Boot", Code.BOLD).append(version, Code.FAINT));
System.out.println(ansi("Hit TAB to complete. Type 'help' and hit "
+ "RETURN for help, and 'exit' to quit."));

View File

@@ -115,7 +115,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
InputStream resourceStream = super.getResourceAsStream(name);
if (resourceStream == null) {
byte[] bytes = this.classResources.get(name);
resourceStream = (bytes != null ? new ByteArrayInputStream(bytes) : null);
resourceStream = (bytes != null) ? new ByteArrayInputStream(bytes) : null;
}
return resourceStream;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -77,7 +77,7 @@ public class ResolveDependencyCoordinatesTransformation
Expression expression = annotation.getMember("value");
if (expression instanceof ConstantExpression) {
Object value = ((ConstantExpression) expression).getValue();
return (value instanceof String ? (String) value : null);
return (value instanceof String) ? (String) value : null;
}
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -42,13 +42,13 @@ public class DependencyManagementArtifactCoordinatesResolver
@Override
public String getGroupId(String artifactId) {
Dependency dependency = find(artifactId);
return (dependency != null ? dependency.getGroupId() : null);
return (dependency != null) ? dependency.getGroupId() : null;
}
@Override
public String getArtifactId(String id) {
Dependency dependency = find(id);
return (dependency != null ? dependency.getArtifactId() : null);
return (dependency != null) ? dependency.getArtifactId() : null;
}
private Dependency find(String id) {
@@ -69,7 +69,7 @@ public class DependencyManagementArtifactCoordinatesResolver
@Override
public String getVersion(String module) {
Dependency dependency = find(module);
return (dependency != null ? dependency.getVersion() : null);
return (dependency != null) ? dependency.getVersion() : null;
}
}

View File

@@ -197,7 +197,7 @@ public class AetherGrapeEngine implements GrapeEngine {
private boolean isTransitive(Map<?, ?> dependencyMap) {
Boolean transitive = (Boolean) dependencyMap.get("transitive");
return (transitive != null ? transitive : true);
return (transitive != null) ? transitive : true;
}
private List<Dependency> getDependencies(DependencyResult dependencyResult) {
@@ -219,7 +219,7 @@ public class AetherGrapeEngine implements GrapeEngine {
private GroovyClassLoader getClassLoader(Map args) {
GroovyClassLoader classLoader = (GroovyClassLoader) args.get("classLoader");
return (classLoader != null ? classLoader : this.classLoader);
return (classLoader != null) ? classLoader : this.classLoader;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -51,9 +51,9 @@ public class DefaultRepositorySystemSessionAutoConfiguration
ProxySelector existing = session.getProxySelector();
if (existing == null || !(existing instanceof CompositeProxySelector)) {
JreProxySelector fallback = new JreProxySelector();
ProxySelector selector = (existing != null
ProxySelector selector = (existing != null)
? new CompositeProxySelector(Arrays.asList(existing, fallback))
: fallback);
: fallback;
session.setProxySelector(selector);
}
}

View File

@@ -67,7 +67,7 @@ public class DependencyResolutionContext {
dependency = this.managedDependencyByGroupAndArtifact
.get(getIdentifier(groupId, artifactId));
}
return (dependency != null ? dependency.getArtifact().getVersion() : null);
return (dependency != null) ? dependency.getArtifact().getVersion() : null;
}
public List<Dependency> getManagedDependencies() {
@@ -104,10 +104,10 @@ public class DependencyResolutionContext {
this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency),
aetherDependency);
}
this.dependencyManagement = (this.dependencyManagement != null
this.dependencyManagement = (this.dependencyManagement != null)
? new CompositeDependencyManagement(dependencyManagement,
this.dependencyManagement)
: dependencyManagement);
: dependencyManagement;
this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver(
this.dependencyManagement);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -150,8 +150,9 @@ public class MavenSettings {
PrintWriter printer = new PrintWriter(message);
printer.println("Failed to determine active profiles:");
for (ModelProblemCollectorRequest problem : problemCollector.getProblems()) {
printer.println(" " + problem.getMessage() + (problem.getLocation() != null
? " at " + problem.getLocation() : ""));
String location = (problem.getLocation() != null)
? " at " + problem.getLocation() : "";
printer.println(" " + problem.getMessage() + location);
if (problem.getException() != null) {
printer.println(indentStackTrace(problem.getException(), " "));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -88,8 +88,8 @@ public abstract class AbstractHttpClientMockTests {
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
mockHttpEntity(response, request.content, request.contentType);
mockStatus(response, 200);
String header = (request.fileName != null
? contentDispositionValue(request.fileName) : null);
String header = (request.fileName != null)
? contentDispositionValue(request.fileName) : null;
mockHttpHeader(response, "Content-Disposition", header);
given(this.http.execute(argThat(getForNonMetadata()))).willReturn(response);
}
@@ -119,8 +119,8 @@ public abstract class AbstractHttpClientMockTests {
try {
HttpEntity entity = mock(HttpEntity.class);
given(entity.getContent()).willReturn(new ByteArrayInputStream(content));
Header contentTypeHeader = (contentType != null
? new BasicHeader("Content-Type", contentType) : null);
Header contentTypeHeader = (contentType != null)
? new BasicHeader("Content-Type", contentType) : null;
given(entity.getContentType()).willReturn(contentTypeHeader);
given(response.getEntity()).willReturn(entity);
return entity;
@@ -138,7 +138,7 @@ public abstract class AbstractHttpClientMockTests {
protected void mockHttpHeader(CloseableHttpResponse response, String headerName,
String value) {
Header header = (value != null ? new BasicHeader(headerName, value) : null);
Header header = (value != null) ? new BasicHeader(headerName, value) : null;
given(response.getFirstHeader(headerName)).willReturn(header);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -232,8 +232,8 @@ public class ProjectGenerationRequestTests {
}
public void setBuildAndFormat(String build, String format) {
this.request.setBuild(build != null ? build : "maven");
this.request.setFormat(format != null ? format : "project");
this.request.setBuild((build != null) ? build : "maven");
this.request.setFormat((format != null) ? format : "project");
this.request.setDetectType(true);
}