Skip to content

Commit 1fa1365

Browse files
committed
Polishing.
All of these instanceof checks can also take advantage of Java 17's pattern matching instanceof operator. Related: #1326.
1 parent a7a2726 commit 1fa1365

File tree

5 files changed

+7
-12
lines changed

5 files changed

+7
-12
lines changed

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/MethodEndpoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ public boolean equals(Object o) {
156156
if (this == o) {
157157
return true;
158158
}
159-
if (o instanceof MethodEndpoint) {
160-
MethodEndpoint other = (MethodEndpoint) o;
159+
if (o instanceof MethodEndpoint other) {
161160
return this.bean.equals(other.bean) && this.method.equals(other.method);
162161
}
163162
return false;

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/adapter/XPathParamAnnotationMethodEndpointAdapter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ protected void invokeInternal(MessageContext messageContext, MethodEndpoint meth
127127
Element payloadElement = getRootElement(messageContext.getRequest().getPayloadSource());
128128
Object[] args = getMethodArguments(payloadElement, methodEndpoint.getMethod());
129129
Object result = methodEndpoint.invoke(args);
130-
if (result instanceof Source) {
131-
Source responseSource = (Source) result;
130+
if (result instanceof Source responseSource) {
132131
WebServiceMessage response = messageContext.getResponse();
133132
transform(responseSource, response.getPayloadResult());
134133
}

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/core/EndpointReference.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public boolean equals(Object o) {
9090
if (this == o) {
9191
return true;
9292
}
93-
if (o instanceof EndpointReference) {
94-
EndpointReference other = (EndpointReference) o;
93+
if (o instanceof EndpointReference other) {
9594
return address.equals(other.address);
9695
}
9796
return false;

spring-ws-security/src/main/java/org/springframework/ws/soap/security/wss4j2/Wss4jSecurityInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,7 @@ private void processPrincipal(WSHandlerResult result) {
852852
if (!CollectionUtils.isEmpty(results)) {
853853
WSSecurityEngineResult actionResult = results.get(0);
854854
Principal principal = (Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL);
855-
if (principal instanceof WSUsernameTokenPrincipalImpl) {
856-
WSUsernameTokenPrincipalImpl usernameTokenPrincipal = (WSUsernameTokenPrincipalImpl) principal;
855+
if (principal instanceof WSUsernameTokenPrincipalImpl usernameTokenPrincipal) {
857856
UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(usernameTokenPrincipal);
858857
try {
859858
validationCallbackHandler.handle(new Callback[] { callback });

spring-xml/src/main/java/org/springframework/xml/namespace/QNameEditor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ public void setAsText(String text) throws IllegalArgumentException {
6262
@Override
6363
public String getAsText() {
6464
Object value = getValue();
65-
if (!(value instanceof QName)) {
66-
return "";
67-
} else {
68-
QName qName = (QName) value;
65+
if (value instanceof QName qName) {
6966
String prefix = qName.getPrefix();
7067
if (StringUtils.hasLength(qName.getNamespaceURI()) && StringUtils.hasLength(prefix)) {
7168
return "{" + qName.getNamespaceURI() + "}" + prefix + ":" + qName.getLocalPart();
@@ -74,6 +71,8 @@ public String getAsText() {
7471
} else {
7572
return qName.getLocalPart();
7673
}
74+
} else {
75+
return "";
7776
}
7877
}
7978
}

0 commit comments

Comments
 (0)