Browse Source

Merge pull request #27835 from izeye

* pr/27835:
  Polish formatting
  Polish HttpMethod

Closes gh-27835
pull/27848/head
Stephane Nicoll 4 years ago
parent
commit
db21cbd4af
  1. 20
      spring-web/src/main/java/org/springframework/http/HttpMethod.java

20
spring-web/src/main/java/org/springframework/http/HttpMethod.java

@ -17,8 +17,10 @@ @@ -17,8 +17,10 @@
package org.springframework.http;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -36,11 +38,6 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable { @@ -36,11 +38,6 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable {
private static final long serialVersionUID = -70133475680645360L;
private static final HttpMethod[] values;
private static final Map<String, HttpMethod> mappings = new HashMap<>(16);
/**
* The HTTP method {@code GET}.
* @see <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">HTTP 1.1, section 9.3</a>
@ -89,13 +86,10 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable { @@ -89,13 +86,10 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable {
*/
public static final HttpMethod TRACE = new HttpMethod("TRACE");
private static final HttpMethod[] values = new HttpMethod[] { GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE };
static {
values = new HttpMethod[]{GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE};
for (HttpMethod httpMethod : values) {
mappings.put(httpMethod.name(), httpMethod);
}
}
private static final Map<String, HttpMethod> mappings = Arrays.stream(values)
.collect(Collectors.toUnmodifiableMap(HttpMethod::name, Function.identity()));
private final String name;
@ -126,7 +120,7 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable { @@ -126,7 +120,7 @@ public final class HttpMethod implements Comparable<HttpMethod>, Serializable {
* @return the corresponding {@code HttpMethod}
*/
public static HttpMethod valueOf(String method) {
Assert.notNull(method, "Name must not be null");
Assert.notNull(method, "Method must not be null");
HttpMethod result = mappings.get(method);
if (result != null) {
return result;

Loading…
Cancel
Save