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 022/** 023 * Java 5 enumeration of HTTP request methods. Intended for use 024 * with {@link org.springframework.http.client.ClientHttpRequest} 025 * and {@link org.springframework.web.client.RestTemplate}. 026 * 027 * @author Arjen Poutsma 028 * @author Juergen Hoeller 029 * @since 3.0 030 */ 031public enum HttpMethod { 032 033 GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; 034 035 036 private static final Map<String, HttpMethod> mappings = new HashMap<String, HttpMethod>(16); 037 038 static { 039 for (HttpMethod httpMethod : values()) { 040 mappings.put(httpMethod.name(), httpMethod); 041 } 042 } 043 044 045 /** 046 * Resolve the given method value to an {@code HttpMethod}. 047 * @param method the method value as a String 048 * @return the corresponding {@code HttpMethod}, or {@code null} if not found 049 * @since 4.2.4 050 */ 051 public static HttpMethod resolve(String method) { 052 return (method != null ? mappings.get(method) : null); 053 } 054 055 056 /** 057 * Determine whether this {@code HttpMethod} matches the given 058 * method value. 059 * @param method the method value as a String 060 * @return {@code true} if it matches, {@code false} otherwise 061 * @since 4.2.4 062 */ 063 public boolean matches(String method) { 064 return (this == resolve(method)); 065 } 066 067}