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 020/** 021 * Enumerates the different IP addressing modes. 022 * 023 * @since 1.2.0 024 */ 025public enum IPAddressingMode { 026 027 // Enumeration types. 028 DHCP(0, "DHCP"), 029 STATIC(1, "Static"); 030 031 // Variables. 032 private int id; 033 034 private String name; 035 036 private static HashMap<Integer, IPAddressingMode> lookupTable = new HashMap<Integer, IPAddressingMode>(); 037 038 static { 039 for (IPAddressingMode mode:values()) 040 lookupTable.put(mode.getID(), mode); 041 } 042 043 /** 044 * Class constructor. Instantiates a new {@code IPAddressingMode} enumeration 045 * entry with the given parameters. 046 * 047 * @param id IP addressing mode ID. 048 * @param name IP addressing mode name. 049 */ 050 private IPAddressingMode(int id, String name) { 051 this.id = id; 052 this.name = name; 053 } 054 055 /** 056 * Retrieves the IP addressing mode ID. 057 * 058 * @return IP addressing mode ID. 059 */ 060 public int getID() { 061 return id; 062 } 063 064 /** 065 * Retrieves the IP addressing mode name. 066 * 067 * @return IP addressing mode name. 068 */ 069 public String getName() { 070 return name; 071 } 072 073 /** 074 * Retrieves the IP addressing mode for the given ID. 075 * 076 * @param id ID to retrieve the IP addressing mode. 077 * 078 * @return The IP addressing mode associated with the given ID. 079 */ 080 public static IPAddressingMode get(int id) { 081 return lookupTable.get(id); 082 } 083 084 /* 085 * (non-Javadoc) 086 * @see java.lang.Enum#toString() 087 */ 088 @Override 089 public String toString() { 090 return name; 091 } 092}