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.packet.devicecloud.SendDataRequestPacket;
021
022/**
023 * Enumerates the different options for the {@link SendDataRequestPacket}.
024 * 
025 * @since 1.2.0
026 */
027public enum SendDataRequestOptions {
028
029        // Enumeration types.
030        OVERWRITE(0, "Overwrite"),
031        ARCHIVE(1, "Archive"),
032        APPEND(2, "Append"),
033        TRANSIENT(3, "Transient data (do not store)");
034
035        // Variables.
036        private int id;
037
038        private String name;
039
040        private static HashMap<Integer, SendDataRequestOptions> lookupTable = new HashMap<Integer, SendDataRequestOptions>();
041
042        static {
043                for (SendDataRequestOptions option:values())
044                        lookupTable.put(option.getID(), option);
045        }
046
047        /**
048         * Creates a new {@code SendDataRequestOptions} entry with the given ID.
049         *
050         * @param id Option ID.
051         * @param name Option name.
052         */
053        SendDataRequestOptions(int id, String name) {
054                this.id = id;
055                this.name = name;
056        }
057
058        /**
059         * Retrieves the option ID.
060         *
061         * @return The option ID.
062         */
063        public int getID() {
064                return id;
065        }
066
067        /**
068         * Retrieves the option name.
069         *
070         * @return The option name.
071         */
072        public String getName() {
073                return name;
074        }
075
076        /**
077         * Retrieves the {@code SendDataRequestOptions} for the given ID.
078         *
079         * @param id ID to retrieve.
080         *
081         * @return The {@code SendDataRequestOptions} associated to the given ID.
082         */
083        public static SendDataRequestOptions get(int id) {
084                return lookupTable.get(id);
085        }
086
087        /*
088         * (non-Javadoc)
089         * @see java.lang.Enum#toString()
090         */
091        @Override
092        public String toString() {
093                return name;
094        }
095}