@Test public void testIsNumeric() { assertTrue(ClassUtil.isNumeric("1")); assertTrue(ClassUtil.isNumeric('1')); assertTrue(ClassUtil.isNumeric(1)); assertFalse(ClassUtil.isNumeric("1a")); }
public static boolean isNumeric(Object obj) { if (isNumber(obj)) return true; if (obj.getClass() == char.class || obj.getClass() == Character.class) { char c = ((Character) obj).charValue(); if (c >= '0' && c <= '9') return true; } else if (obj instanceof CharSequence) { try { new BigDecimal(obj.toString()); return true; } catch (NumberFormatException e) {} } return false; }
ClassUtil { public static boolean isNumeric(Object obj) { if (isNumber(obj)) return true; if (obj.getClass() == char.class || obj.getClass() == Character.class) { char c = ((Character) obj).charValue(); if (c >= '0' && c <= '9') return true; } else if (obj instanceof CharSequence) { try { new BigDecimal(obj.toString()); return true; } catch (NumberFormatException e) {} } return false; } }
ClassUtil { public static boolean isNumeric(Object obj) { if (isNumber(obj)) return true; if (obj.getClass() == char.class || obj.getClass() == Character.class) { char c = ((Character) obj).charValue(); if (c >= '0' && c <= '9') return true; } else if (obj instanceof CharSequence) { try { new BigDecimal(obj.toString()); return true; } catch (NumberFormatException e) {} } return false; } private  ClassUtil(); }
ClassUtil { public static boolean isNumeric(Object obj) { if (isNumber(obj)) return true; if (obj.getClass() == char.class || obj.getClass() == Character.class) { char c = ((Character) obj).charValue(); if (c >= '0' && c <= '9') return true; } else if (obj instanceof CharSequence) { try { new BigDecimal(obj.toString()); return true; } catch (NumberFormatException e) {} } return false; } private  ClassUtil(); static boolean isA(Class<?> what, Class<?> interfaceOrSuper); static boolean isA(Object what, Class<?> interfaceOrSuper); static boolean isPrimitiveNumber(Object obj); static boolean isPrimitiveNumber(Class<?> c); static boolean isNumber(Object obj); static boolean isNumber(Class<?> c); static boolean isNumeric(Object obj); static boolean isWrapper(Class<?> cls); }
ClassUtil { public static boolean isNumeric(Object obj) { if (isNumber(obj)) return true; if (obj.getClass() == char.class || obj.getClass() == Character.class) { char c = ((Character) obj).charValue(); if (c >= '0' && c <= '9') return true; } else if (obj instanceof CharSequence) { try { new BigDecimal(obj.toString()); return true; } catch (NumberFormatException e) {} } return false; } private  ClassUtil(); static boolean isA(Class<?> what, Class<?> interfaceOrSuper); static boolean isA(Object what, Class<?> interfaceOrSuper); static boolean isPrimitiveNumber(Object obj); static boolean isPrimitiveNumber(Class<?> c); static boolean isNumber(Object obj); static boolean isNumber(Class<?> c); static boolean isNumeric(Object obj); static boolean isWrapper(Class<?> cls);  }