Modernize code for diamond, isEmpty & pattern matching
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -37,6 +37,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
* @author Jonas Partner
|
||||
* @author Soby Chacko
|
||||
* @author Artem Bilan
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@@ -94,7 +95,7 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
if (prefixProvided) {
|
||||
Map<String, String> namespaceMap = new HashMap<String, String>(1);
|
||||
Map<String, String> namespaceMap = new HashMap<>(1);
|
||||
namespaceMap.put(nsPrefix, nsUri);
|
||||
builder.addConstructorArgValue(namespaceMap);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Mike Bazos
|
||||
* @author liujiong
|
||||
* @author Gary Russell
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
|
||||
@@ -72,7 +73,7 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
}
|
||||
List<Element> xslParameterElements = DomUtils.getChildElementsByTagName(element, "xslt-param");
|
||||
if (!CollectionUtils.isEmpty(xslParameterElements)) {
|
||||
Map<String, Object> xslParameterMappings = new ManagedMap<String, Object>();
|
||||
Map<String, Object> xslParameterMappings = new ManagedMap<>();
|
||||
for (Element xslParameterElement : xslParameterElements) {
|
||||
String name = xslParameterElement.getAttribute("name");
|
||||
String expression = xslParameterElement.getAttribute("expression");
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
* Base class for XPath {@link MessageSelector} implementations.
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public abstract class AbstractXPathMessageSelector implements MessageSelector {
|
||||
|
||||
@@ -49,7 +50,7 @@ public abstract class AbstractXPathMessageSelector implements MessageSelector {
|
||||
* @param namespace namespace URI
|
||||
*/
|
||||
public AbstractXPathMessageSelector(String xPathExpression, String prefix, String namespace) {
|
||||
Map<String, String> namespaces = new HashMap<String, String>();
|
||||
Map<String, String> namespaces = new HashMap<>();
|
||||
namespaces.put(prefix, namespace);
|
||||
this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression, namespaces);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -70,6 +70,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Christian Tzolov
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
|
||||
@@ -216,8 +217,8 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
try {
|
||||
Object payload = message.getPayload();
|
||||
Object result;
|
||||
if (payload instanceof Node) {
|
||||
result = splitNode((Node) payload);
|
||||
if (payload instanceof Node node) {
|
||||
result = splitNode(node);
|
||||
}
|
||||
else {
|
||||
Document document = this.xmlPayloadConverter.convertToDocument(payload);
|
||||
@@ -239,12 +240,12 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
protected int obtainSizeIfPossible(Iterator<?> iterator) {
|
||||
Iterator<?> theIterator = iterator;
|
||||
|
||||
if (iterator instanceof TransformFunctionIterator) {
|
||||
theIterator = ((TransformFunctionIterator) iterator).delegate;
|
||||
if (iterator instanceof TransformFunctionIterator transformFunctionIterator) {
|
||||
theIterator = transformFunctionIterator.delegate;
|
||||
}
|
||||
|
||||
if (theIterator instanceof NodeListIterator) {
|
||||
return ((NodeListIterator) theIterator).nodeList.getLength();
|
||||
if (theIterator instanceof NodeListIterator nodeListIterator) {
|
||||
return nodeListIterator.nodeList.getLength();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -55,6 +55,7 @@ import org.springframework.xml.transform.StringSource;
|
||||
* @author Jonas Partner
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object, Object> {
|
||||
|
||||
@@ -113,22 +114,21 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object,
|
||||
if (this.alwaysUseSourceFactory) {
|
||||
source = this.sourceFactory.createSource(payload);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
source = new StringSource((String) payload);
|
||||
else if (payload instanceof String string) {
|
||||
source = new StringSource(string);
|
||||
}
|
||||
else if (payload instanceof byte[]) {
|
||||
source = new StreamSource(new ByteArrayInputStream((byte[]) payload));
|
||||
else if (payload instanceof byte[] bytes) {
|
||||
source = new StreamSource(new ByteArrayInputStream(bytes));
|
||||
}
|
||||
else if (payload instanceof File) {
|
||||
File file = (File) payload;
|
||||
else if (payload instanceof File file) {
|
||||
inputStream = new FileInputStream(file);
|
||||
source = new StreamSource(inputStream, file.toURI().toASCIIString());
|
||||
}
|
||||
else if (payload instanceof Document) {
|
||||
source = new DOMSource((Document) payload);
|
||||
else if (payload instanceof Document document) {
|
||||
source = new DOMSource(document);
|
||||
}
|
||||
else if (payload instanceof Source) {
|
||||
source = (Source) payload;
|
||||
else if (payload instanceof Source castSource) {
|
||||
source = castSource;
|
||||
}
|
||||
else {
|
||||
source = this.sourceFactory.createSource(payload);
|
||||
@@ -163,9 +163,9 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object,
|
||||
}
|
||||
|
||||
Object maybeUnmarshalMimeMessage(Object payload) throws IOException {
|
||||
if (payload instanceof org.springframework.ws.mime.MimeMessage) {
|
||||
if (payload instanceof org.springframework.ws.mime.MimeMessage mimeMessage) {
|
||||
return org.springframework.ws.support.MarshallingUtils.unmarshal(this.delegate,
|
||||
(org.springframework.ws.mime.MimeMessage) payload);
|
||||
mimeMessage);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
||||
@@ -85,6 +85,7 @@ import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
* @author Mike Bazos
|
||||
* @author Gary Russell
|
||||
* @author Trung Pham
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
public class XsltPayloadTransformer extends AbstractXmlTransformer implements BeanClassLoaderAware {
|
||||
|
||||
@@ -274,14 +275,14 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
|
||||
if (this.alwaysUseResultFactory) {
|
||||
transformedPayload = transformUsingResultFactory(payload, transformer);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
transformedPayload = transformString((String) payload, transformer);
|
||||
else if (payload instanceof String string) {
|
||||
transformedPayload = transformString(string, transformer);
|
||||
}
|
||||
else if (payload instanceof Document) {
|
||||
transformedPayload = transformDocument((Document) payload, transformer);
|
||||
else if (payload instanceof Document document) {
|
||||
transformedPayload = transformDocument(document, transformer);
|
||||
}
|
||||
else if (payload instanceof Source) {
|
||||
transformedPayload = transformSource((Source) payload, payload, transformer);
|
||||
else if (payload instanceof Source source) {
|
||||
transformedPayload = transformSource(source, payload, transformer);
|
||||
}
|
||||
else {
|
||||
// fall back to trying factories
|
||||
@@ -299,14 +300,14 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
|
||||
if (this.alwaysUseSourceFactory) {
|
||||
source = this.sourceFactory.createSource(payload);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
source = new StringSource((String) payload);
|
||||
else if (payload instanceof String string) {
|
||||
source = new StringSource(string);
|
||||
}
|
||||
else if (payload instanceof Document) {
|
||||
source = new DOMSource((Document) payload);
|
||||
else if (payload instanceof Document document) {
|
||||
source = new DOMSource(document);
|
||||
}
|
||||
else if (payload instanceof Source) {
|
||||
source = (Source) payload;
|
||||
else if (payload instanceof Source castSource) {
|
||||
source = castSource;
|
||||
}
|
||||
else {
|
||||
source = this.sourceFactory.createSource(payload);
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -104,8 +105,7 @@ public final class XPathUtils {
|
||||
else if (resultType instanceof NodeMapper<?>) {
|
||||
return (T) expression.evaluateAsObject(node, (NodeMapper<?>) resultType);
|
||||
}
|
||||
else if (resultType instanceof String && RESULT_TYPES.contains(resultType)) {
|
||||
String resType = (String) resultType;
|
||||
else if (resultType instanceof String resType && RESULT_TYPES.contains(resultType)) {
|
||||
if (DOCUMENT_LIST.equals(resType)) {
|
||||
List<Node> nodeList = (List<Node>) XPathEvaluationType.NODE_LIST_RESULT.evaluateXPath(expression,
|
||||
node);
|
||||
|
||||
Reference in New Issue
Block a user