001/** 002 * Copyright (c) 2014 Digi International Inc., 003 * All rights not expressly granted are reserved. 004 * 005 * This Source Code Form is subject to the terms of the Mozilla Public 006 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 007 * You can obtain one at http://mozilla.org/MPL/2.0/. 008 * 009 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 010 * ======================================================================= 011 */ 012package com.digi.xbee.api.models; 013 014import java.util.HashMap; 015 016/** 017 * Enumerates all the possible states of the discovery. Discovery status field 018 * is part of the {@code TransmitStatusPacket} indicating the status of the 019 * discovery when a packet is sent. 020 * 021 * @see com.digi.xbee.api.packet.common.TransmitStatusPacket 022 */ 023public enum XBeeDiscoveryStatus { 024 025 // Enumeration elements 026 DISCOVERY_STATUS_NO_DISCOVERY_OVERHEAD (0x00, "No discovery overhead"), 027 DISCOVERY_STATUS_ADDRESS_DISCOVERY (0x01, "Address discovery"), 028 DISCOVERY_STATUS_ROUTE_DISCOVERY (0x02, "Route discovery"), 029 DISCOVERY_STATUS_ADDRESS_AND_ROUTE (0x03, "Address and route"), 030 DISCOVERY_STATUS_EXTENDED_TIMEOUT_DISCOVERY (0x40, "Extended timeout discovery"), 031 DISCOVERY_STATUS_UNKNOWN (0xFF, "Unknown"); 032 033 // Variables 034 private final int id; 035 036 private final String description; 037 038 private static final HashMap<Integer, XBeeDiscoveryStatus> lookupTable = new HashMap<Integer, XBeeDiscoveryStatus>(); 039 040 static { 041 for (XBeeDiscoveryStatus at:values()) 042 lookupTable.put(at.getId(), at); 043 } 044 045 /** 046 * Class constructor. Instantiates a new enumeration element of type 047 * {@code XBeeDiscoveryStatus} with the given parameters. 048 * 049 * @param id Discovery status ID. 050 * @param description Discovery status description. 051 */ 052 private XBeeDiscoveryStatus(int id, String description) { 053 this.id = id; 054 this.description = description; 055 } 056 057 /** 058 * Returns the discovery status ID. 059 * 060 * @return The discovery status ID. 061 */ 062 public int getId() { 063 return id; 064 } 065 066 /** 067 * Returns the discovery status description. 068 * 069 * @return Discovery status description. 070 */ 071 public String getDescription() { 072 return description; 073 } 074 075 /** 076 * Returns the {@code XBeeDiscoveryStatus} associated to the given ID. 077 * 078 * @param id ID of the {@code XBeeDiscoveryStatus} to retrieve. 079 * 080 * @return The {@code XBeeDiscoveryStatus} associated with the given ID. 081 */ 082 public static XBeeDiscoveryStatus get(int id) { 083 XBeeDiscoveryStatus status = lookupTable.get(id); 084 if (status != null) 085 return status; 086 return XBeeDiscoveryStatus.DISCOVERY_STATUS_UNKNOWN; 087 } 088 089 /* 090 * (non-Javadoc) 091 * @see java.lang.Enum#toString() 092 */ 093 @Override 094 public String toString() { 095 return description; 096 } 097}