001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.http; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.springframework.lang.Nullable; 023 024/** 025 * Java 5 enumeration of HTTP request methods. Intended for use 026 * with {@link org.springframework.http.client.ClientHttpRequest} 027 * and {@link org.springframework.web.client.RestTemplate}. 028 * 029 * @author Arjen Poutsma 030 * @author Juergen Hoeller 031 * @since 3.0 032 */ 033public enum HttpMethod { 034 035 GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; 036 037 038 private static final Map<String, HttpMethod> mappings = new HashMap<>(16); 039 040 static { 041 for (HttpMethod httpMethod : values()) { 042 mappings.put(httpMethod.name(), httpMethod); 043 } 044 } 045 046 047 /** 048 * Resolve the given method value to an {@code HttpMethod}. 049 * @param method the method value as a String 050 * @return the corresponding {@code HttpMethod}, or {@code null} if not found 051 * @since 4.2.4 052 */ 053 @Nullable 054 public static HttpMethod resolve(@Nullable String method) { 055 return (method != null ? mappings.get(method) : null); 056 } 057 058 059 /** 060 * Determine whether this {@code HttpMethod} matches the given 061 * method value. 062 * @param method the method value as a String 063 * @return {@code true} if it matches, {@code false} otherwise 064 * @since 4.2.4 065 */ 066 public boolean matches(String method) { 067 return (this == resolve(method)); 068 } 069 070}