class JsonValueFactory {

    public JsonValue createJsonValue(String string) {
        if (charAtIs(string, 0, '"') && charAtIs(string, string.length() - 1, '"')) {
            return new StringValue(string.substring(1, string.length() - 1));
        } else if ("true".equalsIgnoreCase(string) || "false".equalsIgnoreCase(string)) {
            return new BooleanValue(Boolean.parseBoolean(string));
        } else if ("null".equalsIgnoreCase(string)) {
            return new NullValue();
        } else {
            char c = string.charAt(0);
            if ((c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+') {
                if (c == '0') {
                    if (string.length() > 2 && (string.charAt(1) == 'x' || string.charAt(1) == 'X')) {
                        try {
                            return new LongValue(Long.parseLong(string.substring(2), 16));
                        } catch (NumberFormatException notHexNumber) {
                        }
                    } else {
                        try {
                            return new LongValue(Long.parseLong(string.substring(1), 8));
                        } catch (NumberFormatException notOctNumber) {
                            try {
                                return new LongValue(Long.parseLong(string));
                            } catch (NumberFormatException notLong) {
                                try {
                                    return new DoubleValue(Double.parseDouble(string));
                                } catch (NumberFormatException notNumber) {
                                }
                            }
                        }
                    }
                } else {
                    try {
                        return new LongValue(Long.parseLong(string));
                    } catch (NumberFormatException notLong) {
                        try {
                            return new DoubleValue(Double.parseDouble(string));
                        } catch (NumberFormatException notNumber) {
                        }
                    }
                }
            }
        }
        return new StringValue(string);
    }

}