001/*
002 * Copyright 2019, 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 XBee local interfaces used in the Relay API packets.
022 *
023 * @since 1.3.0
024 */
025public enum XBeeLocalInterface {
026
027        // Enumeration types
028        SERIAL(0, "Serial port"),
029        BLUETOOTH(1, "Bluetooth Low Energy"),
030        MICROPYTHON(2, "MicroPython"),
031        UNKNOWN(-1, "Unknown");
032
033        // Variables
034        private int id;
035
036        private String description;
037
038        private static HashMap<Integer, XBeeLocalInterface> lookupTable = new HashMap<>();
039
040        static {
041                for (XBeeLocalInterface localInterface : values())
042                        lookupTable.put(localInterface.getID(), localInterface);
043        }
044
045        /**
046         * Class constructor. Instantiates a new {@code XBeeLocalInterface} entry
047         * with the given parameters.
048         *
049         * @param id {@code XBeeLocalInterface} ID code.
050         * @param description {@code XBeeLocalInterface} description.
051         */
052        XBeeLocalInterface(int id, String description) {
053                this.id = id;
054                this.description = description;
055        }
056
057        /**
058         * Retrieves the {@code XBeeLocalInterface} ID code.
059         *
060         * @return {@code XBeeLocalInterface} ID code.
061         */
062        public int getID() {
063                return id;
064        }
065
066        /**
067         * Retrieves the {@code XBeeLocalInterface} description.
068         *
069         * @return {@code XBeeLocalInterface} description.
070         */
071        public String getDescription() {
072                return description;
073        }
074
075        /**
076         * Retrieves the {@code XBeeLocalInterface} for the given ID code.
077         *
078         * @param id ID code to retrieve the {@code XBeeLocalInterface}.
079         *
080         * @return The {@code XBeeLocalInterface} associated with the given ID code,
081         *         {@code UNKNOWN} if there is not any XBee local interface
082         *         associated to the provided ID.
083         */
084        public static XBeeLocalInterface get(int id) {
085                if (lookupTable.get(id) != null)
086                        return lookupTable.get(id);
087                return UNKNOWN;
088        }
089}