@Test(expected=NumberFormatException.class) public void parseLongValueTooLarge() { Tags.parseLong("18446744073709551616"); }
public static long parseLong(final CharSequence s) { final int n = s.length(); if (n == 0) { throw new NumberFormatException("Empty string"); } char c = s.charAt(0); int i = 1; if (c < '0' && (c == '+' || c == '-')) { if (n == 1) { throw new NumberFormatException("Just a sign, no value: " + s); } else if (n > 20) { throw new NumberFormatException("Value too long: " + s); } c = s.charAt(1); i = 2; } else if (n > 19) { throw new NumberFormatException("Value too long: " + s); } long v = 0; do { if ('0' <= c && c <= '9') { v -= c - '0'; } else { throw new NumberFormatException("Invalid character '" + c + "' in " + s); } if (i == n) { break; } v *= 10; c = s.charAt(i++); } while (true); if (v > 0) { throw new NumberFormatException("Overflow in " + s); } else if (s.charAt(0) == '-') { return v; } else if (v == Long.MIN_VALUE) { throw new NumberFormatException("Overflow in " + s); } else { return -v; } }
Tags { public static long parseLong(final CharSequence s) { final int n = s.length(); if (n == 0) { throw new NumberFormatException("Empty string"); } char c = s.charAt(0); int i = 1; if (c < '0' && (c == '+' || c == '-')) { if (n == 1) { throw new NumberFormatException("Just a sign, no value: " + s); } else if (n > 20) { throw new NumberFormatException("Value too long: " + s); } c = s.charAt(1); i = 2; } else if (n > 19) { throw new NumberFormatException("Value too long: " + s); } long v = 0; do { if ('0' <= c && c <= '9') { v -= c - '0'; } else { throw new NumberFormatException("Invalid character '" + c + "' in " + s); } if (i == n) { break; } v *= 10; c = s.charAt(i++); } while (true); if (v > 0) { throw new NumberFormatException("Overflow in " + s); } else if (s.charAt(0) == '-') { return v; } else if (v == Long.MIN_VALUE) { throw new NumberFormatException("Overflow in " + s); } else { return -v; } } }
Tags { public static long parseLong(final CharSequence s) { final int n = s.length(); if (n == 0) { throw new NumberFormatException("Empty string"); } char c = s.charAt(0); int i = 1; if (c < '0' && (c == '+' || c == '-')) { if (n == 1) { throw new NumberFormatException("Just a sign, no value: " + s); } else if (n > 20) { throw new NumberFormatException("Value too long: " + s); } c = s.charAt(1); i = 2; } else if (n > 19) { throw new NumberFormatException("Value too long: " + s); } long v = 0; do { if ('0' <= c && c <= '9') { v -= c - '0'; } else { throw new NumberFormatException("Invalid character '" + c + "' in " + s); } if (i == n) { break; } v *= 10; c = s.charAt(i++); } while (true); if (v > 0) { throw new NumberFormatException("Overflow in " + s); } else if (s.charAt(0) == '-') { return v; } else if (v == Long.MIN_VALUE) { throw new NumberFormatException("Overflow in " + s); } else { return -v; } } private  Tags(); }
Tags { public static long parseLong(final CharSequence s) { final int n = s.length(); if (n == 0) { throw new NumberFormatException("Empty string"); } char c = s.charAt(0); int i = 1; if (c < '0' && (c == '+' || c == '-')) { if (n == 1) { throw new NumberFormatException("Just a sign, no value: " + s); } else if (n > 20) { throw new NumberFormatException("Value too long: " + s); } c = s.charAt(1); i = 2; } else if (n > 19) { throw new NumberFormatException("Value too long: " + s); } long v = 0; do { if ('0' <= c && c <= '9') { v -= c - '0'; } else { throw new NumberFormatException("Invalid character '" + c + "' in " + s); } if (i == n) { break; } v *= 10; c = s.charAt(i++); } while (true); if (v > 0) { throw new NumberFormatException("Overflow in " + s); } else if (s.charAt(0) == '-') { return v; } else if (v == Long.MIN_VALUE) { throw new NumberFormatException("Overflow in " + s); } else { return -v; } } private  Tags(); static String[] splitString(final String s, final char c); static void parse(final HashMap<String, String> tags,
                             final String tag); static String parseWithMetric(final String metric,
                                         final HashMap<String, String> tags); static long parseLong(final CharSequence s); static boolean looksLikeInteger(final String value); }
Tags { public static long parseLong(final CharSequence s) { final int n = s.length(); if (n == 0) { throw new NumberFormatException("Empty string"); } char c = s.charAt(0); int i = 1; if (c < '0' && (c == '+' || c == '-')) { if (n == 1) { throw new NumberFormatException("Just a sign, no value: " + s); } else if (n > 20) { throw new NumberFormatException("Value too long: " + s); } c = s.charAt(1); i = 2; } else if (n > 19) { throw new NumberFormatException("Value too long: " + s); } long v = 0; do { if ('0' <= c && c <= '9') { v -= c - '0'; } else { throw new NumberFormatException("Invalid character '" + c + "' in " + s); } if (i == n) { break; } v *= 10; c = s.charAt(i++); } while (true); if (v > 0) { throw new NumberFormatException("Overflow in " + s); } else if (s.charAt(0) == '-') { return v; } else if (v == Long.MIN_VALUE) { throw new NumberFormatException("Overflow in " + s); } else { return -v; } } private  Tags(); static String[] splitString(final String s, final char c); static void parse(final HashMap<String, String> tags,
                             final String tag); static String parseWithMetric(final String metric,
                                         final HashMap<String, String> tags); static long parseLong(final CharSequence s); static boolean looksLikeInteger(final String value);  }