001/** 002 * Copyright 2017, Digi International Inc. 003 * 004 * This Source Code Form is subject to the terms of the Mozilla Public 005 * License, v. 2.0. If a copy of the MPL was not distributed with this 006 * file, you can obtain one at http://mozilla.org/MPL/2.0/. 007 * 008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 015 */ 016package com.digi.xbee.api.models; 017 018import java.util.HashMap; 019 020import com.digi.xbee.api.utils.HexUtils; 021 022/** 023 * Enumerates the different HTTP method values. 024 * 025 * @since 1.2.1 026 */ 027public enum HTTPMethodEnum { 028 029 // Enumeration entries 030 EMPTY(0x00, "EMPTY"), 031 GET(0x01, "GET"), 032 POST(0x02, "POST"), 033 PUT(0x03, "PUT"), 034 DELETE(0x04, "DELETE"); 035 036 // Variables 037 private int value; 038 039 private String name; 040 041 private static HashMap<Integer, HTTPMethodEnum> lookupTable = new HashMap<Integer, HTTPMethodEnum>(); 042 043 static { 044 for (HTTPMethodEnum function:values()) 045 lookupTable.put(function.getValue(), function); 046 } 047 048 /** 049 * Class constructor. Instantiates a new {@code HTTPMethodEnum} 050 * enumeration entry with the given parameters. 051 * 052 * @param value HTTP method value. 053 * @param name HTTP method name. 054 */ 055 HTTPMethodEnum(int value, String name) { 056 this.value = value; 057 this.name = name; 058 } 059 060 /** 061 * Returns the HTTP method value. 062 * 063 * @return HTTP method value. 064 */ 065 public int getValue() { 066 return value; 067 } 068 069 /** 070 * Returns the HTTP method name. 071 * 072 * @return HTTP method name. 073 */ 074 public String getName() { 075 return name; 076 } 077 078 /** 079 * Returns the HTTP method associated to the given value. 080 * 081 * @param value HTTP method value to retrieve. 082 * @return The HTTP method for the given value, {@code null} if not exists. 083 */ 084 public static HTTPMethodEnum get(int value) { 085 return lookupTable.get(value); 086 } 087 088 /* 089 * (non-Javadoc) 090 * @see java.lang.Enum#toString() 091 */ 092 public String toString() { 093 return HexUtils.byteToHexString((byte)value) + ": " + name; 094 } 095}