@Test public void isNumberTest() { assertTrue(isNumber("0")); assertTrue(isNumber("1")); assertTrue(isNumber("100")); assertTrue(isNumber("+1")); assertTrue(isNumber("-1")); assertFalse(isNumber("++1")); assertFalse(isNumber("--1")); assertFalse(isNumber("-+1")); assertFalse(isNumber("-")); assertFalse(isNumber("+")); assertFalse(isNumber("+-")); assertTrue(isNumber("1.1")); assertTrue(isNumber("0.1")); assertFalse(isNumber(".1")); assertFalse(isNumber("1.1.0")); assertTrue(isNumber("+0.1")); assertTrue(isNumber("-0.1")); assertFalse(isNumber("+0.")); assertFalse(isNumber("-0.")); assertFalse(isNumber("+.1")); assertFalse(isNumber("-.1")); assertFalse(isNumber("+.")); assertFalse(isNumber("abc")); }
public static boolean isNumber(final String s) { if (isBlank(s)) return false; char c; boolean pointExist = false; int start = s.startsWith(PLUS) || s.startsWith(MINUS) ? 1 : 0; int len = s.length(); int lenMinusOne = len - 1; if (start == len) return false; for (int i = start; i < len; i++) { c = s.charAt(i); if (c == POINT) { if (i == start || i == lenMinusOne || pointExist) return false; else { pointExist = true; continue; } } if (!isDigit(c)) return false; } return true; }
StrUtils { public static boolean isNumber(final String s) { if (isBlank(s)) return false; char c; boolean pointExist = false; int start = s.startsWith(PLUS) || s.startsWith(MINUS) ? 1 : 0; int len = s.length(); int lenMinusOne = len - 1; if (start == len) return false; for (int i = start; i < len; i++) { c = s.charAt(i); if (c == POINT) { if (i == start || i == lenMinusOne || pointExist) return false; else { pointExist = true; continue; } } if (!isDigit(c)) return false; } return true; } }
StrUtils { public static boolean isNumber(final String s) { if (isBlank(s)) return false; char c; boolean pointExist = false; int start = s.startsWith(PLUS) || s.startsWith(MINUS) ? 1 : 0; int len = s.length(); int lenMinusOne = len - 1; if (start == len) return false; for (int i = start; i < len; i++) { c = s.charAt(i); if (c == POINT) { if (i == start || i == lenMinusOne || pointExist) return false; else { pointExist = true; continue; } } if (!isDigit(c)) return false; } return true; } private  StrUtils(); }
StrUtils { public static boolean isNumber(final String s) { if (isBlank(s)) return false; char c; boolean pointExist = false; int start = s.startsWith(PLUS) || s.startsWith(MINUS) ? 1 : 0; int len = s.length(); int lenMinusOne = len - 1; if (start == len) return false; for (int i = start; i < len; i++) { c = s.charAt(i); if (c == POINT) { if (i == start || i == lenMinusOne || pointExist) return false; else { pointExist = true; continue; } } if (!isDigit(c)) return false; } return true; } private  StrUtils(); static String fillWithZero(Number aim, int num); static String getMainValue(String suppressCode, int headIndex, String needRemoved); static boolean isEmpty(final String s); static boolean isNotEmpty(final String s); static boolean isBlank(String s); static boolean isNotBlank(String s); static String cutStartStr(String origin, String start); static String cutMiddleStr(String origin, String middle); static String cutTailStr(String origin, String tail); static LinkedList<String> splitMulti(String origin, final String... separators); static boolean isLike(final String origin, final String aim, final String... ignores); static boolean isNumber(final String s); static String str2Hex(String s); static String hex2Str(String s); static String compression(String s); }
StrUtils { public static boolean isNumber(final String s) { if (isBlank(s)) return false; char c; boolean pointExist = false; int start = s.startsWith(PLUS) || s.startsWith(MINUS) ? 1 : 0; int len = s.length(); int lenMinusOne = len - 1; if (start == len) return false; for (int i = start; i < len; i++) { c = s.charAt(i); if (c == POINT) { if (i == start || i == lenMinusOne || pointExist) return false; else { pointExist = true; continue; } } if (!isDigit(c)) return false; } return true; } private  StrUtils(); static String fillWithZero(Number aim, int num); static String getMainValue(String suppressCode, int headIndex, String needRemoved); static boolean isEmpty(final String s); static boolean isNotEmpty(final String s); static boolean isBlank(String s); static boolean isNotBlank(String s); static String cutStartStr(String origin, String start); static String cutMiddleStr(String origin, String middle); static String cutTailStr(String origin, String tail); static LinkedList<String> splitMulti(String origin, final String... separators); static boolean isLike(final String origin, final String aim, final String... ignores); static boolean isNumber(final String s); static String str2Hex(String s); static String hex2Str(String s); static String compression(String s); static final String ZERO; static final String HEX; static final String COLON; static final String COMMA; static final String DOUBLE_TRANSFER; static final String PLUS; static final String MINUS; static final char POINT; static final String NEXT_LINE; }