Use enhanced switch expressions where feasible

Closes gh-28014
This commit is contained in:
a.yazychyan
2022-02-07 20:51:32 +03:00
committed by Sam Brannen
parent 42d114534b
commit c5c926726d
38 changed files with 291 additions and 493 deletions

View File

@@ -154,18 +154,10 @@ final class Jackson2Tokenizer {
private void updateDepth(JsonToken token) {
switch (token) {
case START_OBJECT:
this.objectDepth++;
break;
case END_OBJECT:
this.objectDepth--;
break;
case START_ARRAY:
this.arrayDepth++;
break;
case END_ARRAY:
this.arrayDepth--;
break;
case START_OBJECT -> this.objectDepth++;
case END_OBJECT -> this.objectDepth--;
case START_ARRAY -> this.arrayDepth++;
case END_ARRAY -> this.arrayDepth--;
}
}

View File

@@ -164,12 +164,9 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
String message = getErrorMessage(statusCode.value(), statusText, body, charset);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw HttpClientErrorException.create(message, statusCode, statusText, headers, body, charset);
case SERVER_ERROR:
throw HttpServerErrorException.create(message, statusCode, statusText, headers, body, charset);
default:
throw new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset);
case CLIENT_ERROR -> throw HttpClientErrorException.create(message, statusCode, statusText, headers, body, charset);
case SERVER_ERROR -> throw HttpServerErrorException.create(message, statusCode, statusText, headers, body, charset);
default -> throw new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset);
}
}

View File

@@ -154,20 +154,11 @@ public class MockPageContext extends PageContext {
public void setAttribute(String name, @Nullable Object value, int scope) {
Assert.notNull(name, "Attribute name must not be null");
switch (scope) {
case PAGE_SCOPE:
setAttribute(name, value);
break;
case REQUEST_SCOPE:
this.request.setAttribute(name, value);
break;
case SESSION_SCOPE:
this.request.getSession().setAttribute(name, value);
break;
case APPLICATION_SCOPE:
this.servletContext.setAttribute(name, value);
break;
default:
throw new IllegalArgumentException("Invalid scope: " + scope);
case PAGE_SCOPE -> setAttribute(name, value);
case REQUEST_SCOPE -> this.request.setAttribute(name, value);
case SESSION_SCOPE -> this.request.getSession().setAttribute(name, value);
case APPLICATION_SCOPE -> this.servletContext.setAttribute(name, value);
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
}
}
@@ -226,20 +217,11 @@ public class MockPageContext extends PageContext {
public void removeAttribute(String name, int scope) {
Assert.notNull(name, "Attribute name must not be null");
switch (scope) {
case PAGE_SCOPE:
this.attributes.remove(name);
break;
case REQUEST_SCOPE:
this.request.removeAttribute(name);
break;
case SESSION_SCOPE:
this.request.getSession().removeAttribute(name);
break;
case APPLICATION_SCOPE:
this.servletContext.removeAttribute(name);
break;
default:
throw new IllegalArgumentException("Invalid scope: " + scope);
case PAGE_SCOPE -> this.attributes.remove(name);
case REQUEST_SCOPE -> this.request.removeAttribute(name);
case SESSION_SCOPE -> this.request.getSession().removeAttribute(name);
case APPLICATION_SCOPE -> this.servletContext.removeAttribute(name);
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
}
}