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