Modernize code for diamond, isEmpty & pattern matching
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2023 the original author or authors.
|
||||
* Copyright 2017-2024 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.
|
||||
@@ -52,6 +52,7 @@ import org.springframework.validation.Validator;
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Trung Pham
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -311,14 +312,14 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
|
||||
|
||||
private HttpStatus buildHttpStatus(Object httpStatusValue) {
|
||||
HttpStatus httpStatus = null;
|
||||
if (httpStatusValue instanceof HttpStatus) {
|
||||
httpStatus = (HttpStatus) httpStatusValue;
|
||||
if (httpStatusValue instanceof HttpStatus castHttpStatus) {
|
||||
httpStatus = castHttpStatus;
|
||||
}
|
||||
else if (httpStatusValue instanceof Integer) {
|
||||
httpStatus = HttpStatus.valueOf((Integer) httpStatusValue);
|
||||
else if (httpStatusValue instanceof Integer integer) {
|
||||
httpStatus = HttpStatus.valueOf(integer);
|
||||
}
|
||||
else if (httpStatusValue instanceof String) {
|
||||
httpStatus = HttpStatus.valueOf(Integer.parseInt((String) httpStatusValue));
|
||||
else if (httpStatusValue instanceof String string) {
|
||||
httpStatus = HttpStatus.valueOf(Integer.parseInt(string));
|
||||
}
|
||||
return httpStatus;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
* @author Shiliang Li
|
||||
* @author Florian Schöffl
|
||||
* @author Christian Tzolov
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -404,7 +405,7 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
|
||||
private HttpEntity<?> createHttpEntityFromMessage(Message<?> message, HttpMethod httpMethod) {
|
||||
HttpHeaders httpHeaders = mapHeaders(message);
|
||||
if (shouldIncludeRequestBody(httpMethod)) {
|
||||
return new HttpEntity<Object>(message, httpHeaders);
|
||||
return new HttpEntity<>(message, httpHeaders);
|
||||
}
|
||||
return new HttpEntity<>(httpHeaders);
|
||||
}
|
||||
@@ -447,11 +448,11 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
|
||||
for (Entry<?, ?> entry : simpleMap.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof Object[]) {
|
||||
value = Arrays.asList((Object[]) value);
|
||||
if (value instanceof Object[] objects) {
|
||||
value = Arrays.asList(objects);
|
||||
}
|
||||
if (value instanceof Collection) {
|
||||
multipartValueMap.put(key, new ArrayList<>((Collection<?>) value));
|
||||
if (value instanceof Collection<?> collection) {
|
||||
multipartValueMap.put(key, new ArrayList<>(collection));
|
||||
}
|
||||
else {
|
||||
multipartValueMap.add(key, value);
|
||||
@@ -502,8 +503,8 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
|
||||
Assert.state((httpMethod instanceof String || httpMethod instanceof HttpMethod), () ->
|
||||
"'httpMethodExpression' evaluation must result in an 'HttpMethod' enum or its String representation, " +
|
||||
"not: " + (httpMethod == null ? "null" : httpMethod.getClass()));
|
||||
if (httpMethod instanceof HttpMethod) {
|
||||
return (HttpMethod) httpMethod;
|
||||
if (httpMethod instanceof HttpMethod castHttpMethod) {
|
||||
return castHttpMethod;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
@@ -537,9 +538,9 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
|
||||
() -> "The '" + property + "' can be an instance of 'Class<?>', 'String' " +
|
||||
"or 'ParameterizedTypeReference<?>'; " +
|
||||
"evaluation resulted in a " + typeClass + ".");
|
||||
if (type instanceof String && StringUtils.hasText((String) type)) {
|
||||
if (type instanceof String string && StringUtils.hasText(string)) {
|
||||
try {
|
||||
type = ClassUtils.forName((String) type, getApplicationContext().getClassLoader());
|
||||
type = ClassUtils.forName(string, getApplicationContext().getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException("Cannot load class for name: " + type, e);
|
||||
|
||||
Reference in New Issue
Block a user