Skip to content

Commit 3ee777e

Browse files
committed
Polish ternary expressions
Consistently format ternary expressions and always favor `!=` as the the check.
1 parent 690f946 commit 3ee777e

File tree

199 files changed

+419
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+419
-412
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public EnvironmentEndpoint environmentEndpoint() {
114114
@Bean
115115
@ConditionalOnMissingBean
116116
public HealthEndpoint healthEndpoint() {
117-
return new HealthEndpoint(
118-
this.healthAggregator == null ? new OrderedHealthAggregator()
119-
: this.healthAggregator,
120-
this.healthIndicators == null
121-
? Collections.<String, HealthIndicator>emptyMap()
122-
: this.healthIndicators);
117+
HealthAggregator healthAggregator = (this.healthAggregator != null
118+
? this.healthAggregator : new OrderedHealthAggregator());
119+
Map<String, HealthIndicator> healthIndicators = (this.healthIndicators != null
120+
? this.healthIndicators
121+
: Collections.<String, HealthIndicator>emptyMap());
122+
return new HealthEndpoint(healthAggregator, healthIndicators);
123123
}
124124

125125
@Bean
@@ -131,8 +131,8 @@ public BeansEndpoint beansEndpoint() {
131131
@Bean
132132
@ConditionalOnMissingBean
133133
public InfoEndpoint infoEndpoint() throws Exception {
134-
return new InfoEndpoint(this.infoContributors == null
135-
? Collections.<InfoContributor>emptyList() : this.infoContributors);
134+
return new InfoEndpoint(this.infoContributors != null ? this.infoContributors
135+
: Collections.<InfoContributor>emptyList());
136136
}
137137

138138
@Bean
@@ -156,8 +156,8 @@ public MetricsEndpoint metricsEndpoint() {
156156
@Bean
157157
@ConditionalOnMissingBean
158158
public TraceEndpoint traceEndpoint() {
159-
return new TraceEndpoint(this.traceRepository == null
160-
? new InMemoryTraceRepository() : this.traceRepository);
159+
return new TraceEndpoint(this.traceRepository != null ? this.traceRepository
160+
: new InMemoryTraceRepository());
161161
}
162162

163163
@Bean

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ private boolean isHypermediaDisabled(MethodParameter returnType) {
340340
private String getPath(ServletServerHttpRequest request) {
341341
String path = (String) request.getServletRequest()
342342
.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
343-
return (path == null ? "" : path);
343+
return (path != null ? path : "");
344344
}
345345

346346
}
@@ -355,8 +355,8 @@ private static class EndpointResource extends ResourceSupport {
355355

356356
@SuppressWarnings("unchecked")
357357
EndpointResource(Object content, String path) {
358-
this.content = content instanceof Map ? null : content;
359-
this.embedded = (Map<String, Object>) (this.content == null ? content : null);
358+
this.content = (content instanceof Map ? null : content);
359+
this.embedded = (Map<String, Object>) (this.content != null ? null : content);
360360
add(linkTo(Object.class).slash(path).withSelfRel());
361361
}
362362

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ public EndpointWebMvcManagementContextConfiguration(
8989
this.corsProperties = corsProperties;
9090
List<EndpointHandlerMappingCustomizer> providedCustomizers = mappingCustomizers
9191
.getIfAvailable();
92-
this.mappingCustomizers = providedCustomizers == null
93-
? Collections.<EndpointHandlerMappingCustomizer>emptyList()
94-
: providedCustomizers;
92+
this.mappingCustomizers = (providedCustomizers != null ? providedCustomizers
93+
: Collections.<EndpointHandlerMappingCustomizer>emptyList());
9594
}
9695

9796
@Bean

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected DataSourceHealthIndicator createHealthIndicator(DataSource source) {
231231
private String getValidationQuery(DataSource source) {
232232
DataSourcePoolMetadata poolMetadata = this.poolMetadataProvider
233233
.getDataSourcePoolMetadata(source);
234-
return (poolMetadata == null ? null : poolMetadata.getValidationQuery());
234+
return (poolMetadata != null ? poolMetadata.getValidationQuery() : null);
235235
}
236236

237237
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/LinksEnhancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private String getRel(MvcEndpoint endpoint) {
7474
private void addEndpointLink(ResourceSupport resource, MvcEndpoint endpoint,
7575
String rel) {
7676
Class<?> type = endpoint.getEndpointType();
77-
type = (type == null ? Object.class : type);
77+
type = (type != null ? type : Object.class);
7878
if (StringUtils.hasText(rel)) {
7979
String href = this.rootPath + endpoint.getPath();
8080
resource.add(linkTo(type).slash(href).withRel(rel));

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationsImportSelector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ private static final class ManagementConfiguration implements Ordered {
111111
private int readOrder(AnnotationMetadata annotationMetadata) {
112112
Map<String, Object> attributes = annotationMetadata
113113
.getAnnotationAttributes(Order.class.getName());
114-
Integer order = (attributes == null ? null
115-
: (Integer) attributes.get("value"));
116-
return (order == null ? Ordered.LOWEST_PRECEDENCE : order);
114+
Integer order = (attributes != null ? (Integer) attributes.get("value")
115+
: null);
116+
return (order != null ? order : Ordered.LOWEST_PRECEDENCE);
117117
}
118118

119119
public String getClassName() {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public SchedulingConfigurer metricWritersMetricExporter(
9595
exporters.setReader(reader);
9696
exporters.setWriters(writers);
9797
}
98-
exporters.setExporters(this.exporters == null
99-
? Collections.<String, Exporter>emptyMap() : this.exporters);
98+
exporters.setExporters(this.exporters != null ? this.exporters
99+
: Collections.<String, Exporter>emptyMap());
100100
return exporters;
101101
}
102102

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ public SystemPublicMetrics systemPublicMetrics() {
8989

9090
@Bean
9191
public MetricReaderPublicMetrics metricReaderPublicMetrics() {
92-
return new MetricReaderPublicMetrics(new CompositeMetricReader(
93-
this.metricReaders == null ? new MetricReader[0] : this.metricReaders
94-
.toArray(new MetricReader[this.metricReaders.size()])));
92+
MetricReader[] readers = (this.metricReaders != null
93+
? this.metricReaders.toArray(new MetricReader[this.metricReaders.size()])
94+
: new MetricReader[0]);
95+
return new MetricReaderPublicMetrics(new CompositeMetricReader(readers));
9596
}
9697

9798
@Bean

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public abstract class AbstractJmxCacheStatisticsProvider<C extends Cache>
5656
public CacheStatistics getCacheStatistics(CacheManager cacheManager, C cache) {
5757
try {
5858
ObjectName objectName = internalGetObjectName(cache);
59-
return (objectName == null ? null : getCacheStatistics(objectName));
59+
return (objectName != null ? getCacheStatistics(objectName) : null);
6060
}
6161
catch (MalformedObjectNameException ex) {
6262
throw new IllegalStateException(ex);

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private CloudFoundrySecurityService getCloudFoundrySecurityService(
8989
String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
9090
boolean skipSslValidation = cloudFoundryProperties
9191
.getProperty("skip-ssl-validation", Boolean.class, false);
92-
return cloudControllerUrl == null ? null : new CloudFoundrySecurityService(
93-
restTemplateBuilder, cloudControllerUrl, skipSslValidation);
92+
return (cloudControllerUrl != null ? new CloudFoundrySecurityService(
93+
restTemplateBuilder, cloudControllerUrl, skipSslValidation) : null);
9494
}
9595

9696
private CorsConfiguration getCorsConfiguration() {

0 commit comments

Comments
 (0)