1 10 11 package com.sun.jmx.snmp; 12 13 14 import java.io.*; 15 import java.util.Hashtable ; 16 import java.util.*; 17 18 19 20 35 36 abstract public class Enumerated implements Serializable { 37 38 43 public Enumerated() throws IllegalArgumentException { 44 Enumeration e =getIntTable().keys() ; 45 if (e.hasMoreElements()) { 46 value = ((Integer )e.nextElement()).intValue() ; 47 } 48 else { 49 throw new IllegalArgumentException () ; 50 } 51 } 52 53 60 public Enumerated(int valueIndex) throws IllegalArgumentException { 61 if (getIntTable().get(new Integer (valueIndex)) == null) { 62 throw new IllegalArgumentException () ; 63 } 64 value = valueIndex ; 65 } 66 67 74 public Enumerated(Integer valueIndex) throws IllegalArgumentException { 75 if (getIntTable().get(valueIndex) == null) { 76 throw new IllegalArgumentException () ; 77 } 78 value = valueIndex.intValue() ; 79 } 80 81 82 89 public Enumerated(String valueString) throws IllegalArgumentException { 90 Integer index = (Integer )getStringTable().get(valueString) ; 91 if (index == null) { 92 throw new IllegalArgumentException () ; 93 } 94 else { 95 value = index.intValue() ; 96 } 97 } 98 99 100 105 106 public int intValue() { 107 return value ; 108 } 109 110 111 116 117 public Enumeration valueIndexes() { 118 return getIntTable().keys() ; 119 } 120 121 122 127 128 public Enumeration valueStrings() { 129 return getStringTable().keys() ; 130 } 131 132 133 143 public boolean equals(Object obj) { 144 145 return ((obj != null) && 146 (getClass() == obj.getClass()) && 147 (value == ((Enumerated)obj).value)) ; 148 } 149 150 151 156 public int hashCode() { 157 String hashString = getClass().getName() + String.valueOf(value) ; 158 return hashString.hashCode() ; 159 } 160 161 162 167 168 public String toString() { 169 return (String )getIntTable().get(new Integer (value)) ; 170 } 171 172 173 182 183 protected abstract Hashtable getIntTable() ; 184 185 186 187 196 197 protected abstract Hashtable getStringTable() ; 198 199 200 204 protected int value ; 205 206 } 207 | Popular Tags |