src/share/classes/sun/tools/jconsole/inspector/Utils.java

Print this page
rev 10203 : 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
Reviewed-by: chegar, prappo
Contributed-by: Otavio Santana <otaviojava@java.net>


 325         try {
 326             return Double.valueOf(value);
 327         } catch (NumberFormatException e2) {
 328         // OK: Ignore exception...
 329         }
 330         throw new NumberFormatException("Cannot convert string value '" +
 331                 value + "' into a numerical value");
 332     }
 333 
 334     /**
 335      * This method attempts to create an object of the given "type"
 336      * using the "value" parameter.
 337      * e.g. calling createObjectFromString("java.lang.Integer", "10")
 338      * will return an Integer object initialized to 10.
 339      */
 340     public static Object createObjectFromString(String type, String value)
 341             throws Exception {
 342         Object result;
 343         if (primitiveToWrapper.containsKey(type)) {
 344             if (type.equals(Character.TYPE.getName())) {
 345                 result = new Character(value.charAt(0));
 346             } else {
 347                 result = newStringConstructor(
 348                         ((Class<?>) primitiveToWrapper.get(type)).getName(),
 349                         value);
 350             }
 351         } else if (type.equals(Character.class.getName())) {
 352             result = new Character(value.charAt(0));
 353         } else if (Number.class.isAssignableFrom(Utils.getClass(type))) {
 354             result = createNumberFromStringValue(value);
 355         } else if (value == null || value.equals("null")) {
 356             // hack for null value
 357             result = null;
 358         } else {
 359             // try to create a Java object using
 360             // the one-string-param constructor
 361             result = newStringConstructor(type, value);
 362         }
 363         return result;
 364     }
 365 
 366     /**
 367      * This method is responsible for converting the inputs given by the user
 368      * into a useful object array for passing into a parameter array.
 369      */
 370     public static Object[] getParameters(XTextField[] inputs, String[] params)
 371             throws Exception {
 372         Object result[] = new Object[inputs.length];




 325         try {
 326             return Double.valueOf(value);
 327         } catch (NumberFormatException e2) {
 328         // OK: Ignore exception...
 329         }
 330         throw new NumberFormatException("Cannot convert string value '" +
 331                 value + "' into a numerical value");
 332     }
 333 
 334     /**
 335      * This method attempts to create an object of the given "type"
 336      * using the "value" parameter.
 337      * e.g. calling createObjectFromString("java.lang.Integer", "10")
 338      * will return an Integer object initialized to 10.
 339      */
 340     public static Object createObjectFromString(String type, String value)
 341             throws Exception {
 342         Object result;
 343         if (primitiveToWrapper.containsKey(type)) {
 344             if (type.equals(Character.TYPE.getName())) {
 345                 result = value.charAt(0);
 346             } else {
 347                 result = newStringConstructor(
 348                         ((Class<?>) primitiveToWrapper.get(type)).getName(),
 349                         value);
 350             }
 351         } else if (type.equals(Character.class.getName())) {
 352             result = value.charAt(0);
 353         } else if (Number.class.isAssignableFrom(Utils.getClass(type))) {
 354             result = createNumberFromStringValue(value);
 355         } else if (value == null || value.equals("null")) {
 356             // hack for null value
 357             result = null;
 358         } else {
 359             // try to create a Java object using
 360             // the one-string-param constructor
 361             result = newStringConstructor(type, value);
 362         }
 363         return result;
 364     }
 365 
 366     /**
 367      * This method is responsible for converting the inputs given by the user
 368      * into a useful object array for passing into a parameter array.
 369      */
 370     public static Object[] getParameters(XTextField[] inputs, String[] params)
 371             throws Exception {
 372         Object result[] = new Object[inputs.length];