Use switch expression where feasible
This commit is contained in:
committed by
Sam Brannen
parent
8ed04b5dd1
commit
490b5c77fc
@@ -186,17 +186,20 @@ final class SerializableTypeWrapper {
|
||||
@Nullable
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
switch (method.getName()) {
|
||||
case "equals":
|
||||
case "equals" -> {
|
||||
Object other = args[0];
|
||||
// Unwrap proxies for speed
|
||||
if (other instanceof Type otherType) {
|
||||
other = unwrap(otherType);
|
||||
}
|
||||
return ObjectUtils.nullSafeEquals(this.provider.getType(), other);
|
||||
case "hashCode":
|
||||
}
|
||||
case "hashCode" -> {
|
||||
return ObjectUtils.nullSafeHashCode(this.provider.getType());
|
||||
case "getTypeProvider":
|
||||
}
|
||||
case "getTypeProvider" -> {
|
||||
return this.provider;
|
||||
}
|
||||
}
|
||||
|
||||
if (Type.class == method.getReturnType() && ObjectUtils.isEmpty(args)) {
|
||||
|
||||
@@ -112,24 +112,22 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader {
|
||||
while (true) {
|
||||
XMLEvent event = nextEvent();
|
||||
switch (event.getEventType()) {
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
case XMLStreamConstants.START_ELEMENT, XMLStreamConstants.END_ELEMENT -> {
|
||||
return event;
|
||||
case XMLStreamConstants.END_DOCUMENT:
|
||||
}
|
||||
case XMLStreamConstants.END_DOCUMENT -> {
|
||||
return null;
|
||||
case XMLStreamConstants.SPACE:
|
||||
case XMLStreamConstants.COMMENT:
|
||||
case XMLStreamConstants.PROCESSING_INSTRUCTION:
|
||||
}
|
||||
case XMLStreamConstants.SPACE, XMLStreamConstants.COMMENT, XMLStreamConstants.PROCESSING_INSTRUCTION -> {
|
||||
continue;
|
||||
case XMLStreamConstants.CDATA:
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
}
|
||||
case XMLStreamConstants.CDATA, XMLStreamConstants.CHARACTERS -> {
|
||||
if (!event.asCharacters().isWhiteSpace()) {
|
||||
throw new XMLStreamException(
|
||||
"Non-ignorable whitespace CDATA or CHARACTERS event: " + event);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new XMLStreamException("Expected START_ELEMENT or END_ELEMENT: " + event);
|
||||
}
|
||||
default -> throw new XMLStreamException("Expected START_ELEMENT or END_ELEMENT: " + event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,16 +438,15 @@ class ResourceTests {
|
||||
@Override
|
||||
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
|
||||
if (request.getPath().equals("/resource")) {
|
||||
switch (request.getMethod()) {
|
||||
case "HEAD":
|
||||
return new MockResponse()
|
||||
return switch (request.getMethod()) {
|
||||
case "HEAD" -> new MockResponse()
|
||||
.addHeader("Content-Length", "6");
|
||||
case "GET":
|
||||
return new MockResponse()
|
||||
case "GET" -> new MockResponse()
|
||||
.addHeader("Content-Length", "6")
|
||||
.addHeader("Content-Type", "text/plain")
|
||||
.setBody("Spring");
|
||||
}
|
||||
default -> new MockResponse().setResponseCode(404);
|
||||
};
|
||||
}
|
||||
return new MockResponse().setResponseCode(404);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user