1 55 56 package org.apache.commons.el; 57 58 67 68 class PrimitiveObjects 69 { 70 74 static int BYTE_LOWER_BOUND = 0; 75 static int BYTE_UPPER_BOUND = 255; 76 static int CHARACTER_LOWER_BOUND = 0; 77 static int CHARACTER_UPPER_BOUND = 255; 78 static int SHORT_LOWER_BOUND = -1000; 79 static int SHORT_UPPER_BOUND = 1000; 80 static int INTEGER_LOWER_BOUND = -1000; 81 static int INTEGER_UPPER_BOUND = 1000; 82 static int LONG_LOWER_BOUND = -1000; 83 static int LONG_UPPER_BOUND = 1000; 84 85 89 static Byte [] mBytes = createBytes (); 90 static Character [] mCharacters = createCharacters (); 91 static Short [] mShorts = createShorts (); 92 static Integer [] mIntegers = createIntegers (); 93 static Long [] mLongs = createLongs (); 94 95 public static Boolean getBoolean (boolean pValue) 99 { 100 return 101 pValue ? 102 Boolean.TRUE : 103 Boolean.FALSE; 104 } 105 106 public static Byte getByte (byte pValue) 108 { 109 if (pValue >= BYTE_LOWER_BOUND && 110 pValue <= BYTE_UPPER_BOUND) { 111 return mBytes [((int) pValue) - BYTE_LOWER_BOUND]; 112 } 113 else { 114 return new Byte (pValue); 115 } 116 } 117 118 public static Character getCharacter (char pValue) 120 { 121 if (pValue >= CHARACTER_LOWER_BOUND && 122 pValue <= CHARACTER_UPPER_BOUND) { 123 return mCharacters [((int) pValue) - CHARACTER_LOWER_BOUND]; 124 } 125 else { 126 return new Character (pValue); 127 } 128 } 129 130 public static Short getShort (short pValue) 132 { 133 if (pValue >= SHORT_LOWER_BOUND && 134 pValue <= SHORT_UPPER_BOUND) { 135 return mShorts [((int) pValue) - SHORT_LOWER_BOUND]; 136 } 137 else { 138 return new Short (pValue); 139 } 140 } 141 142 public static Integer getInteger (int pValue) 144 { 145 if (pValue >= INTEGER_LOWER_BOUND && 146 pValue <= INTEGER_UPPER_BOUND) { 147 return mIntegers [((int) pValue) - INTEGER_LOWER_BOUND]; 148 } 149 else { 150 return new Integer (pValue); 151 } 152 } 153 154 public static Long getLong (long pValue) 156 { 157 if (pValue >= LONG_LOWER_BOUND && 158 pValue <= LONG_UPPER_BOUND) { 159 return mLongs [((int) pValue) - LONG_LOWER_BOUND]; 160 } 161 else { 162 return new Long (pValue); 163 } 164 } 165 166 public static Float getFloat (float pValue) 168 { 169 return new Float (pValue); 170 } 171 172 public static Double getDouble (double pValue) 174 { 175 return new Double (pValue); 176 } 177 178 186 public static Class getPrimitiveObjectClass (Class pClass) 187 { 188 if (pClass == Boolean.TYPE) { 189 return Boolean .class; 190 } 191 else if (pClass == Byte.TYPE) { 192 return Byte .class; 193 } 194 else if (pClass == Short.TYPE) { 195 return Short .class; 196 } 197 else if (pClass == Character.TYPE) { 198 return Character .class; 199 } 200 else if (pClass == Integer.TYPE) { 201 return Integer .class; 202 } 203 else if (pClass == Long.TYPE) { 204 return Long .class; 205 } 206 else if (pClass == Float.TYPE) { 207 return Float .class; 208 } 209 else if (pClass == Double.TYPE) { 210 return Double .class; 211 } 212 else { 213 return pClass; 214 } 215 } 216 217 static Byte [] createBytes () 221 { 222 int len = BYTE_UPPER_BOUND - BYTE_LOWER_BOUND + 1; 223 Byte [] ret = new Byte [len]; 224 byte val = (byte) BYTE_LOWER_BOUND; 225 for (int i = 0; i < len; i++, val++) { 226 ret [i] = new Byte (val); 227 } 228 return ret; 229 } 230 231 static Character [] createCharacters () 233 { 234 int len = CHARACTER_UPPER_BOUND - CHARACTER_LOWER_BOUND + 1; 235 Character [] ret = new Character [len]; 236 char val = (char) CHARACTER_LOWER_BOUND; 237 for (int i = 0; i < len; i++, val++) { 238 ret [i] = new Character (val); 239 } 240 return ret; 241 } 242 243 static Short [] createShorts () 245 { 246 int len = SHORT_UPPER_BOUND - SHORT_LOWER_BOUND + 1; 247 Short [] ret = new Short [len]; 248 short val = (short) SHORT_LOWER_BOUND; 249 for (int i = 0; i < len; i++, val++) { 250 ret [i] = new Short (val); 251 } 252 return ret; 253 } 254 255 static Integer [] createIntegers () 257 { 258 int len = INTEGER_UPPER_BOUND - INTEGER_LOWER_BOUND + 1; 259 Integer [] ret = new Integer [len]; 260 int val = (int) INTEGER_LOWER_BOUND; 261 for (int i = 0; i < len; i++, val++) { 262 ret [i] = new Integer (val); 263 } 264 return ret; 265 } 266 267 static Long [] createLongs () 269 { 270 int len = LONG_UPPER_BOUND - LONG_LOWER_BOUND + 1; 271 Long [] ret = new Long [len]; 272 long val = (long) LONG_LOWER_BOUND; 273 for (int i = 0; i < len; i++, val++) { 274 ret [i] = new Long (val); 275 } 276 return ret; 277 } 278 279 281 } 282 | Popular Tags |