StringUtil { public static boolean isDouble(String str) { if (null == str || "".equals(str)) { return false; } Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$"); return pattern.matcher(str).matches(); } private  StringUtil(); static boolean isNullOrEmpty(String str); static boolean isInteger(String str); static boolean isDouble(String str); static String upFirstChar(String Str); static String lowerFirstChar(String s);  }
@Test public void testIsDoubleNullOrEmpty() { Assert.assertFalse(StringUtil.isDouble(null)); Assert.assertFalse(StringUtil.isDouble("")); }
@Test public void testIsDoubleTrue() { Assert.assertTrue(StringUtil.isDouble("-1")); Assert.assertTrue(StringUtil.isDouble("-1.")); Assert.assertTrue(StringUtil.isDouble("1.")); Assert.assertTrue(StringUtil.isDouble("1.")); Assert.assertTrue(StringUtil.isDouble("+1")); Assert.assertTrue(StringUtil.isDouble("+1.")); Assert.assertTrue(StringUtil.isDouble("+")); Assert.assertTrue(StringUtil.isDouble("-")); Assert.assertTrue(StringUtil.isDouble("+.")); Assert.assertTrue(StringUtil.isDouble("-.")); }
@Test public void testIsDoubleFalse() { Assert.assertFalse(StringUtil.isDouble("--")); Assert.assertFalse(StringUtil.isDouble("++")); Assert.assertFalse(StringUtil.isDouble("a")); }