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.io;
017
018import java.util.HashMap;
019
020/**
021 * Enumerates the possible values of a {@code IOLine} configured as digital 
022 * I/O.
023 * 
024 * @see IOLine
025 */
026public enum IOValue {
027
028        // Enumeration types.
029        LOW(4, "Low"),
030        HIGH(5, "High");
031        
032        // Variables.
033        private final static HashMap <Integer, IOValue> lookupTable = new HashMap<Integer, IOValue>();
034        
035        private final int id;
036        
037        private final String name;
038        
039        static {
040                for (IOValue ioValue:values())
041                        lookupTable.put(ioValue.getID(), ioValue);
042        }
043        
044        /**
045         * Class constructor. Instantiates a new {@code IOValue} enumeration entry 
046         * with the given parameters.
047         * 
048         * @param id IO value ID.
049         * @param name IO value name.
050         */
051        private IOValue(int id, String name) {
052                this.id = id;
053                this.name = name;
054        }
055        
056        /**
057         * Returns the ID of the IO value.
058         * 
059         * @return The ID of the IO value.
060         */
061        public int getID() {
062                return id;
063        }
064        
065        /**
066         * Returns the name of the IO value.
067         * 
068         * @return The name of the IO value.
069         */
070        public String getName() {
071                return name;
072        }
073        
074        /**
075         * Returns the {@code IOValue} associated to the provided value ID.
076         * 
077         * @param valueID The ID of the {@code IOValue} to retrieve.
078         * 
079         * @return The {@code IOValue} associated to the provided value ID.
080         */
081        public static IOValue getIOValue(int valueID) {
082                if (lookupTable.containsKey(valueID))
083                        return lookupTable.get(valueID);
084                return null;
085        }
086        
087        /*
088         * (non-Javadoc)
089         * @see java.lang.Enum#toString()
090         */
091        @Override
092        public String toString() {
093                return name;
094        }
095}