public static boolean isNumber(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        int sz = str.length();
        boolean hasExp = false;
        boolean hasDecPoint = false;
        boolean allowSigns = false;
        boolean foundDigit = false;
        // deal with any possible sign up front
        int start = (str.charAt(0) == '-') ? 1 : 0;
        if (sz > start + 1) {
            if (str.charAt(start) == '0' && str.charAt(start + 1) == 'x') {
                int i = start + 2;
                if (i == sz) {
                    return false; // str == "0x"
                }
                // checking hex (it can't be anything else)
                for (; i < str.length(); i++) {
                    char ch = str.charAt(i);
                    if ((ch < '0' || ch > '9')
                            && (ch < 'a' || ch > 'f')
                            && (ch < 'A' || ch > 'F')) {
                        return false;
                    }
                }
                return true;
            }
        }
        sz--; // don't want to loop to the last char, check it afterwords
        // for type qualifiers
        int i = start;
        // loop to the next to last char or to the last char if we need another digit to
        // make a valid number (e.g. chars[0..5] = "1234E")
        while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) {
            char ch = str.charAt(i);
            if (ch >= '0' && ch <= '9') {
                foundDigit = true;
                allowSigns = false;

            } else if (ch == '.') {
                if (hasDecPoint || hasExp) {
                    // two decimal points or dec in exponent
                    return false;
                }
                hasDecPoint = true;
            } else if (ch == 'e' || ch == 'E') {
                // we've already taken care of hex.
                if (hasExp) {
                    // two E's
                    return false;
                }
                if (!foundDigit) {
                    return false;
                }
                hasExp = true;
                allowSigns = true;
            } else if (ch == '+' || ch == '-') {
                if (!allowSigns) {
                    return false;
                }
                allowSigns = false;
                foundDigit = false; // we need a digit after the E
            } else {
                return false;
            }
            i++;
        }
        if (i < str.length()) {
            char ch = str.charAt(i);

            if (ch >= '0' && ch <= '9') {
                // no type qualifier, OK
                return true;
            }
            if (ch == 'e' || ch == 'E') {
                // can't have an E at the last byte
                return false;
            }
            if (!allowSigns
                    && (ch == 'd'
                    || ch == 'D'
                    || ch == 'f'
                    || ch == 'F')) {
                return foundDigit;
            }
            if (ch == 'l'
                    || ch == 'L') {
                // not allowing L with an exponent
                return foundDigit && !hasExp;
            }
            // last character is illegal
            return false;
        }
        // allowSigns is true iff the val ends in 'E'
        // found digit it to make sure weird stuff like '.' and '1E-' doesn't pass
        return !allowSigns && foundDigit;
    }
@Test
    public void testIsNumberStringInput() {
        Assert.assertTrue(StringUtils.isNumber("-0x3"));
        Assert.assertTrue(StringUtils.isNumber("2"));
        Assert.assertTrue(StringUtils.isNumber("5L"));
        Assert.assertTrue(StringUtils.isNumber("0e+3"));

        Assert.assertFalse(StringUtils.isNumber(""));
        Assert.assertFalse(StringUtils.isNumber("-0x"));
        Assert.assertFalse(StringUtils.isNumber("0xh"));
        Assert.assertFalse(StringUtils.isNumber("0x\u0018"));
        Assert.assertFalse(StringUtils.isNumber("0xAc\u8040????????"));
        Assert.assertFalse(
                StringUtils.isNumber("0x3c\\u8040????????????????????????"));
        Assert.assertFalse(StringUtils.isNumber("..."));
        Assert.assertFalse(StringUtils.isNumber("-0eE#"));
        Assert.assertFalse(StringUtils.isNumber("E.."));
        Assert.assertFalse(StringUtils.isNumber("2.+L"));
        Assert.assertFalse(StringUtils.isNumber("a/b/c"));
        Assert.assertFalse(StringUtils.isNumber("E"));
        Assert.assertFalse(StringUtils.isNumber("e"));
        Assert.assertFalse(StringUtils.isNumber("-d"));
        Assert.assertFalse(StringUtils.isNumber("-D"));
        Assert.assertFalse(StringUtils.isNumber("-f"));
        Assert.assertFalse(StringUtils.isNumber("-F"));
        Assert.assertFalse(StringUtils.isNumber("-l"));
        Assert.assertFalse(StringUtils.isNumber("\'"));
        Assert.assertFalse(StringUtils.isNumber("-"));
    }