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
020/**
021 * Enumerates the different RestFul statuses.
022 * 
023 * @since 1.2.1
024 */
025public enum RestFulStatusEnum {
026
027        // Enumeration types.
028        SUCCESS(0x0200, "Success"),
029        CREATED(0x0201, "Success: Created"),
030        ACCEPTED(0x0202, "Success: Accepted"),
031        NON_AUTHORITATIVE(0x0203, "Success: Non-Authoritative Information"),
032        NO_CONTENT(0x0204, "Success: No Content"),
033        RESET_CONTENT(0x0205, "Success: Reset Content"),
034        CLIENT_ERROR_BAD_REQUEST(0x0400, "Client Error: Bad Request"),
035        CLIENT_ERROR_UNAUTHORIZED(0x0401, "Client Error: Unauthorized"),
036        CLIENT_ERROR_BAD_OPTION(0x0402, "Client Error: Bad Option"),
037        CLIENT_ERROR_FORBIDDEN(0x0403, "Client Error: Forbidden"),
038        CLIENT_ERROR_NOT_FOUND(0x0404, "Client Error: Not Found"),
039        CLIENT_ERROR_NOT_ALLOWED(0x0405, "Client Error: Method Not Allowed"),
040        CLIENT_ERROR_NOT_ACCEPTED(0x0406, "Client Error: Not Accepted"),
041        CLIENT_ERROR_PRECONDITION_FAILED(0x0412, "Client Error: Precondition Failed"),
042        CLIENT_ERROR_ENTITY_TOO_LARGE(0x0413, "Client Error: Request Entity Too Large"),
043        CLIENT_ERROR_UNSUPPORTED_FORMAT(0x0415, "Client Error: Unsupported Content Format"),
044        SERVER_ERROR(0x0500, "Server Error"),
045        SERVER_ERROR_BAD_GATEWAY(0x0502, "Server Error: Bad Gateway"),
046        SERVER_ERROR_SERVICE_UNAVAILABLE(0x0503, "Server Error: Service Unavailable"),
047        SERVER_ERROR_GATEWAY_TIMEOUT(0x0504, "Server Error: Gateway Timeout"),
048        SERVER_ERROR_PROXYING_NOT_SUPPORTED(0x0505, "Server Error: Proxying Not Supported");
049
050        // Variables
051        private final int id;
052        
053        private final String description;
054        
055        private final static HashMap<Integer, RestFulStatusEnum> lookupTable = new HashMap<Integer, RestFulStatusEnum>();
056        
057        static {
058                for (RestFulStatusEnum status:values())
059                        lookupTable.put(status.getID(), status);
060        }
061
062        /**
063         * Class constructor. Instantiates a new {@code RestFulStatusEnum} enumeration
064         * entry with the given parameters.
065         *
066         * @param id RestFul status id.
067         * @param description RestFul status description.
068         */
069        private RestFulStatusEnum(int id, String description) {
070                this.id = id;
071                this.description = description;
072        }
073
074        /**
075         * Retrieves the RestFul status ID.
076         *
077         * @return RestFul status ID.
078         */
079        public int getID() {
080                return id;
081        }
082
083        /**
084         * Retrieves the RestFul status description.
085         *
086         * @return RestFul status description.
087         */
088        public String getDescription() {
089                return description;
090        }
091
092        /**
093         * Retrieves the RestFul status for the given ID.
094         *
095         * @param id ID to retrieve the RestFul status.
096         *
097         * @return The RestFul status associated with the given ID.
098         */
099        public static RestFulStatusEnum get(int id) {
100                return lookupTable.get(id);
101        }
102
103        /*
104         * (non-Javadoc)
105         * @see java.lang.Enum#toString()
106         */
107        @Override
108        public String toString() {
109                return description + " [" + id + "]";
110        }
111}