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 Device Cloud statuses. 022 * 023 * @since 1.2.0 024 */ 025public enum DeviceCloudStatus { 026 027 // Enumeration types. 028 SUCCESS(0x00, "Success"), 029 BAD_REQUEST(0x01, "Bad request"), 030 RESPONSE_UNAVAILABLE(0x02, "Response unavailable"), 031 DEVICE_CLOUD_ERROR(0x03, "Device Cloud error"), 032 CANCELED(0x20, "Device Request canceled by user"), 033 TIME_OUT(0x21, "Session timed out"), 034 UNKNOWN_ERROR(0x40, "Unknown error"); 035 036 // Variables. 037 private int id; 038 039 private String name; 040 041 private static HashMap<Integer, DeviceCloudStatus> lookupTable = new HashMap<Integer, DeviceCloudStatus>(); 042 043 static { 044 for (DeviceCloudStatus status:values()) 045 lookupTable.put(status.getID(), status); 046 } 047 048 /** 049 * Creates a new {@code DeviceCloudStatus} entry with the given ID. 050 * 051 * @param id Status ID. 052 * @param name Status name. 053 */ 054 DeviceCloudStatus(int id, String name) { 055 this.id = id; 056 this.name = name; 057 } 058 059 /** 060 * Retrieves the status ID. 061 * 062 * @return The Status ID. 063 */ 064 public int getID() { 065 return id; 066 } 067 068 /** 069 * Retrieves the status name. 070 * 071 * @return The status name. 072 */ 073 public String getName() { 074 return name; 075 } 076 077 /** 078 * Retrieves the {@code DeviceCloudStatus} for the given ID. 079 * 080 * @param id ID to retrieve. 081 * 082 * @return The {@code DeviceCloudStatus} associated to the given ID. 083 */ 084 public static DeviceCloudStatus get(int id) { 085 return lookupTable.get(id); 086 } 087 088 /* 089 * (non-Javadoc) 090 * @see java.lang.Enum#toString() 091 */ 092 @Override 093 public String toString() { 094 return name; 095 } 096}