PropertiesUtil { public static long toLong(Object propValue, long defaultValue) { propValue = toObject(propValue); if (propValue instanceof Long) { return (Long) propValue; } else if (propValue != null) { try { return Long.parseLong(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("UnnecessaryBoxing") @Test public void testToLong() { assertEquals(2, PropertiesUtil.toLong(null, 2)); assertEquals(2, PropertiesUtil.toLong(1.0, 2)); assertEquals(2, PropertiesUtil.toLong(new Double(1.0), 2)); assertEquals(5, PropertiesUtil.toLong(new Long(5), 2)); assertEquals(5, PropertiesUtil.toLong(new Integer(5), 2)); assertEquals(2, PropertiesUtil.toLong("abc", 2)); }