Use consistent ternary expression style

Update all ternary expressions so that the condition is always in
parentheses and "not equals" is used in the test. This helps to bring
consistency across the codebase which makes ternary expression easier
to scan.

For example: `a = (a != null) ? a : b`

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-30 00:31:13 -07:00
committed by Rob Winch
parent 8d3f039f76
commit 834dcf5bcf
131 changed files with 277 additions and 265 deletions

View File

@@ -128,7 +128,7 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg
return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication).flatMap((a) -> {
Object p = resolvePrincipal(parameter, a.getPrincipal());
Mono<Object> principal = Mono.justOrEmpty(p);
return adapter == null ? principal : Mono.just(adapter.fromPublisher(principal));
return (adapter != null) ? Mono.just(adapter.fromPublisher(principal)) : principal;
});
}

View File

@@ -127,7 +127,7 @@ public class CurrentSecurityContextArgumentResolver implements HandlerMethodArgu
return ReactiveSecurityContextHolder.getContext().flatMap((securityContext) -> {
Object sc = resolveSecurityContext(parameter, securityContext);
Mono<Object> result = Mono.justOrEmpty(sc);
return adapter == null ? result : Mono.just(adapter.fromPublisher(result));
return (adapter != null) ? Mono.just(adapter.fromPublisher(result)) : result;
});
}

View File

@@ -113,7 +113,7 @@ public final class SimpDestinationMessageMatcher implements MessageMatcher<Objec
}
this.matcher = pathMatcher;
this.messageTypeMatcher = type == null ? ANY_MESSAGE : new SimpMessageTypeMatcher(type);
this.messageTypeMatcher = (type != null) ? new SimpMessageTypeMatcher(type) : ANY_MESSAGE;
this.pattern = pattern;
}
@@ -129,7 +129,7 @@ public final class SimpDestinationMessageMatcher implements MessageMatcher<Objec
public Map<String, String> extractPathVariables(Message<?> message) {
final String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders());
return destination != null ? this.matcher.extractUriTemplateVariables(this.pattern, destination)
return (destination != null) ? this.matcher.extractUriTemplateVariables(this.pattern, destination)
: Collections.emptyMap();
}

View File

@@ -48,8 +48,8 @@ public final class CsrfChannelInterceptor extends ChannelInterceptorAdapter {
}
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(message.getHeaders());
CsrfToken expectedToken = sessionAttributes == null ? null
: (CsrfToken) sessionAttributes.get(CsrfToken.class.getName());
CsrfToken expectedToken = (sessionAttributes != null)
? (CsrfToken) sessionAttributes.get(CsrfToken.class.getName()) : null;
if (expectedToken == null) {
throw new MissingCsrfTokenException(null);

View File

@@ -220,10 +220,10 @@ public final class ResolvableMethod {
private String formatParameter(Parameter param) {
Annotation[] anns = param.getAnnotations();
return (anns.length > 0
return (anns.length > 0)
? Arrays.stream(anns).map(this::formatAnnotation).collect(Collectors.joining(",", "[", "]")) + " "
+ param
: param.toString());
: param.toString();
}
private String formatAnnotation(Annotation annotation) {
@@ -591,9 +591,9 @@ public final class ResolvableMethod {
*/
@SafeVarargs
public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotationTypes) {
this.filters.add((param) -> (annotationTypes.length > 0
this.filters.add((param) -> (annotationTypes.length > 0)
? Arrays.stream(annotationTypes).noneMatch(param::hasParameterAnnotation)
: param.getParameterAnnotations().length == 0));
: param.getParameterAnnotations().length == 0);
return this;
}