001 package frysk.rsl; 002 003 public class Level 004 extends Number 005 implements Comparable 006 { 007 private final String enumString; 008 private final int enumValue; 009 private final String enumPrint; 010 private final String enumName; 011 private Level (int value, String string, String print, String name) 012 { 013 enumString = string; 014 enumValue = value; 015 enumPrint = print; 016 enumName = name; 017 } 018 /** Return the qualified name of the enum. */ 019 public String toString () 020 { 021 return enumString; 022 } 023 /** Return a printable version of the enum. */ 024 public String toPrint () 025 { 026 return enumPrint; 027 } 028 /** Return the name of just the enum. */ 029 public String toName () 030 { 031 return enumName; 032 } 033 /** 034 * Return true if OBJECT has the same value. 035 */ 036 public boolean equals (Object o) 037 { 038 if (o == null) 039 return false; 040 if (! (o instanceof Level)) 041 return false; 042 return ((Level)o).intValue() == this.intValue(); 043 } 044 public int hashCode () 045 { 046 return enumValue; 047 } 048 public int compareTo (Object o) 049 { 050 Level rhs = (Level) o; // Can throw - ok. 051 return this.enumValue - rhs.enumValue; 052 } 053 static public final int NONE_ = 0; 054 static public final Level NONE = new Level (0, "Level_NONE", "NONE", "NONE"); 055 static public final int WARNING_ = 1; 056 static public final Level WARNING = new Level (1, "Level_WARNING", "WARNING", "WARNING"); 057 static public final int INFO_ = 2; 058 static public final Level INFO = new Level (2, "Level_INFO", "INFO", "INFO"); 059 static public final int DEFAULT_ = INFO_; 060 static public final Level DEFAULT = INFO; 061 static public final int FINE_ = 3; 062 static public final Level FINE = new Level (3, "Level_FINE", "FINE", "FINE"); 063 static public final int FINEST_ = 4; 064 static public final Level FINEST = new Level (4, "Level_FINEST", "FINEST", "FINEST"); 065 static public final int MAX_ = 5; 066 static public final Level MAX = new Level (5, "Level_MAX", "MAX", "MAX"); 067 068 /** Create a HashMap containing all the Level elements. */ 069 private static java.util.Map getMap () 070 { 071 java.util.Map map; 072 map = new java.util.HashMap (); 073 map.put (NONE.enumName, NONE); 074 map.put (WARNING.enumName, WARNING); 075 map.put (INFO.enumName, INFO); 076 map.put (FINE.enumName, FINE); 077 map.put (FINEST.enumName, FINEST); 078 map.put (MAX.enumName, MAX); 079 return map; 080 } 081 private static java.util.Map enumMap = getMap (); 082 083 /** Return the Level object that matches the string. */ 084 public static Level valueOf (String string) 085 { 086 return (Level)enumMap.get (string); 087 } 088 089 /** Return the Level object that matches the integer. */ 090 public static Level valueOf (long i) 091 { 092 switch ((int)i) { 093 case NONE_: return NONE; 094 case WARNING_: return WARNING; 095 case INFO_: return INFO; 096 case FINE_: return FINE; 097 case FINEST_: return FINEST; 098 case MAX_: return MAX; 099 default: return null; 100 } 101 } 102 103 /** Return an array of all the Level elements. */ 104 public static Level[] values () 105 { 106 return (Level[]) enumMap.values ().toArray (new Level[0]); 107 } 108 109 /** 110 * Returns the full underscore delimited name of the 111 * field corresponding to the value I. 112 */ 113 static public String toString (long i) 114 { 115 Level c = valueOf (i); 116 if (c == null) 117 return "_0x" + Long.toHexString (i); 118 else 119 return c.toString (); 120 } 121 122 /** 123 * Returns the printable (or user readable) name for the 124 * field corresponding to the value I. 125 */ 126 static public String toPrintString (long i) 127 { 128 Level c = valueOf (i); 129 if (c == null) 130 return "_0x" + Long.toHexString (i); 131 else 132 return c.toPrint (); 133 } 134 135 /** 136 * Returns the printable (or user readable) name for the 137 * field corresponding to the value I, or DEF is there 138 * is no such field. 139 */ 140 static public String toPrintString (long i, String def) 141 { 142 Level c = valueOf (i); 143 if (c == null) 144 return def; 145 else 146 return c.toPrint (); 147 } 148 149 /** 150 * Returns just the name part of the num corresponding to I. 151 */ 152 static public String toName (long i) 153 { 154 Level c = valueOf (i); 155 if (c == null) 156 return "_0x" + Long.toHexString (i); 157 else 158 return c.toName (); 159 } 160 161 /** 162 * Returns just the name part of the num corresponding to I, 163 * or DEF is there is no such field. 164 */ 165 static public String toName (long i, String def) 166 { 167 Level c = valueOf (i); 168 if (c == null) 169 return def; 170 else 171 return c.toName (); 172 } 173 174 /** 175 * Return the equivalent of the enum. 176 */ 177 public int intValue () { 178 return enumValue; 179 } 180 181 /** 182 * Return the equivalent of the enum. 183 */ 184 public long longValue () { 185 return enumValue; 186 } 187 188 /** 189 * Return the equivalent of the enum. 190 */ 191 public float floatValue () { 192 return enumValue; 193 } 194 195 /** 196 * Return the equivalent of the enum. 197 */ 198 public double doubleValue () { 199 return enumValue; 200 } 201 202 static final long serialVersionUID = 0; 203 }