Polish ternary expressions

Consistently format ternary expressions and always favor `!=` as the
the check.
This commit is contained in:
Phillip Webb
2018-05-02 12:41:51 -07:00
parent 690f946b6d
commit 3ee777e142
199 changed files with 419 additions and 412 deletions

View File

@@ -95,8 +95,8 @@ public class RemoteDevToolsAutoConfiguration {
@Bean
public HandlerMapper remoteDevToolsHealthCheckHandlerMapper() {
Handler handler = new HttpStatusHandler();
return new UrlHandlerMapper((this.serverProperties.getContextPath() == null ? ""
: this.serverProperties.getContextPath())
return new UrlHandlerMapper((this.serverProperties.getContextPath() != null
? this.serverProperties.getContextPath() : "")
+ this.properties.getRemote().getContextPath(), handler);
}
@@ -136,8 +136,8 @@ public class RemoteDevToolsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(name = "remoteRestartHandlerMapper")
public UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server) {
String url = (this.serverProperties.getContextPath() == null ? ""
: this.serverProperties.getContextPath())
String url = (this.serverProperties.getContextPath() != null
? this.serverProperties.getContextPath() : "")
+ this.properties.getRemote().getContextPath() + "/restart";
logger.warn("Listening for remote restart updates on " + url);
Handler handler = new HttpRestartServerHandler(server);
@@ -162,8 +162,8 @@ public class RemoteDevToolsAutoConfiguration {
@ConditionalOnMissingBean(name = "remoteDebugHandlerMapper")
public UrlHandlerMapper remoteDebugHandlerMapper(
@Qualifier("remoteDebugHttpTunnelServer") HttpTunnelServer server) {
String url = (this.serverProperties.getContextPath() == null ? ""
: this.serverProperties.getContextPath())
String url = (this.serverProperties.getContextPath() != null
? this.serverProperties.getContextPath() : "")
+ this.properties.getRemote().getContextPath() + "/debug";
logger.warn("Listening for remote debug traffic on " + url);
Handler handler = new HttpTunnelServerHandler(server);

View File

@@ -44,7 +44,7 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
File home = getHomeFolder();
File propertyFile = (home == null ? null : new File(home, FILE_NAME));
File propertyFile = (home != null ? new File(home, FILE_NAME) : null);
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
FileSystemResource resource = new FileSystemResource(propertyFile);
Properties properties;

View File

@@ -135,7 +135,7 @@ public class ClassPathChangeUploader
private void logUpload(ClassLoaderFiles classLoaderFiles) {
int size = classLoaderFiles.size();
logger.info(
"Uploaded " + size + " class " + (size == 1 ? "resource" : "resources"));
"Uploaded " + size + " class " + (size != 1 ? "resources" : "resource"));
}
private byte[] serialize(ClassLoaderFiles classLoaderFiles) throws IOException {
@@ -162,10 +162,10 @@ public class ClassPathChangeUploader
private ClassLoaderFile asClassLoaderFile(ChangedFile changedFile)
throws IOException {
ClassLoaderFile.Kind kind = TYPE_MAPPINGS.get(changedFile.getType());
byte[] bytes = (kind == Kind.DELETED ? null
: FileCopyUtils.copyToByteArray(changedFile.getFile()));
long lastModified = (kind == Kind.DELETED ? System.currentTimeMillis()
: changedFile.getFile().lastModified());
byte[] bytes = (kind != Kind.DELETED
? FileCopyUtils.copyToByteArray(changedFile.getFile()) : null);
long lastModified = (kind != Kind.DELETED ? changedFile.getFile().lastModified()
: System.currentTimeMillis());
return new ClassLoaderFile(kind, lastModified, bytes);
}

View File

@@ -55,8 +55,8 @@ public class ClassLoaderFile implements Serializable {
*/
public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) {
Assert.notNull(kind, "Kind must not be null");
Assert.isTrue(kind == Kind.DELETED ? contents == null : contents != null,
"Contents must " + (kind == Kind.DELETED ? "" : "not ") + "be null");
Assert.isTrue(kind != Kind.DELETED ? contents != null : contents == null,
"Contents must " + (kind != Kind.DELETED ? "not " : "") + "be null");
this.kind = kind;
this.lastModified = lastModified;
this.contents = contents;

View File

@@ -91,8 +91,8 @@ public class HttpTunnelConnection implements TunnelConnection {
throw new IllegalArgumentException("Malformed URL '" + url + "'");
}
this.requestFactory = requestFactory;
this.executor = (executor == null
? Executors.newCachedThreadPool(new TunnelThreadFactory()) : executor);
this.executor = (executor != null ? executor
: Executors.newCachedThreadPool(new TunnelThreadFactory()));
}
@Override

View File

@@ -139,7 +139,7 @@ public class ClassPathChangeUploaderTests {
private void assertClassFile(ClassLoaderFile file, String content, Kind kind) {
assertThat(file.getContents())
.isEqualTo(content == null ? null : content.getBytes());
.isEqualTo(content != null ? content.getBytes() : null);
assertThat(file.getKind()).isEqualTo(kind);
}