PropertiesUtil { public static double toDouble(Object propValue, double defaultValue) { propValue = toObject(propValue); if (propValue instanceof Double) { return (Double) propValue; } else if (propValue != null) { try { return Double.parseDouble(String.valueOf(propValue)); } catch (NumberFormatException nfe) { } } return defaultValue; } private  PropertiesUtil(); static boolean toBoolean(Object propValue, boolean defaultValue); static String toString(Object propValue, String defaultValue); static long toLong(Object propValue, long defaultValue); static int toInteger(Object propValue, int defaultValue); static double toDouble(Object propValue, double defaultValue); static Object toObject(Object propValue); static String[] toStringArray(Object propValue); static String[] toStringArray(Object propValue, String[] defaultArray); @SuppressWarnings("unchecked") static void populate(Object instance, Map<String,?> config, boolean validate);  }
@SuppressWarnings({"deprecation", "UnnecessaryBoxing"}) @Test public void testToDouble() { assertEquals(2.0, PropertiesUtil.toDouble(null, 2.0), 0); assertEquals(1.0, PropertiesUtil.toDouble(1.0, 2.0), 0); assertEquals(1.0, PropertiesUtil.toDouble(new Double(1.0), 2.0), 0); assertEquals(5.0, PropertiesUtil.toDouble(new Long(5), 2.0), 0); assertEquals(2.0, PropertiesUtil.toDouble("abc", 2.0), 0); }