1 11 12 package org.jivesoftware.util; 13 14 import java.util.*; 15 16 28 public class IntEnum extends Enum { 29 30 private int value; 31 protected static Hashtable enumTypes = new Hashtable(); 32 33 protected IntEnum(String name, int val) { 34 super(name); 35 this.value = val; 36 } 37 38 43 public int getValue() { 44 return value; 45 } 46 47 public boolean equals(Object object) { 48 if (this == object) { 49 return true; 50 } 51 else if ((this.getClass().isInstance(object)) && value == (((IntEnum)object).value)) { 52 return true; 53 } 54 else { 55 return false; 56 } 57 } 58 59 64 protected static void register(IntEnum enumeration) { 65 Map enums = (Map)enumTypes.get(enumeration.getClass()); 66 if (enums == null) { 67 enums = new HashMap<Integer ,Object >(); 68 enumTypes.put(enumeration.getClass(), enums); 69 } 70 enums.put(enumeration.getValue(), enumeration); 71 } 72 73 80 protected static IntEnum getEnumFromInt(Class enumClass, int value) { 81 Map enums = (Map)enumTypes.get(enumClass); 82 if (enums != null) { 83 return (IntEnum)enums.get(value); 84 } 85 return null; 86 } 87 88 public int hashCode() { 89 return value; 90 } 91 92 public String toString() { 93 return Integer.toString(value) + " " + super.toString(); 94 } 95 } | Popular Tags |