/** * Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed as * an unsigned {@code int} value in the specified radix. * * @throws NumberFormatException if the string does not contain a parsable unsigned {@code int} * value */ public static UnsignedInteger valueOf(String string, int radix) { return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix)); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * <p><b>Java 8 users:</b> use {@link Integer#parseUnsignedInt(String)} instead. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null (in contrast to {@link * Integer#parseInt(String)}) */ @CanIgnoreReturnValue public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed as * an unsigned {@code int} value in the specified radix. * * @throws NumberFormatException if the string does not contain a parsable unsigned {@code int} * value */ public static UnsignedInteger valueOf(String string, int radix) { return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix)); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * <p><b>Java 8 users:</b> use {@link Integer#parseUnsignedInt(String)} instead. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null (in contrast to {@link * Integer#parseInt(String)}) */ @CanIgnoreReturnValue public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * <p><b>Java 8 users:</b> use {@link Integer#parseUnsignedInt(String)} instead. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null (in contrast to {@link * Integer#parseInt(String)}) */ @CanIgnoreReturnValue public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed as * an unsigned {@code int} value in the specified radix. * * @throws NumberFormatException if the string does not contain a parsable unsigned {@code int} * value */ public static UnsignedInteger valueOf(String string, int radix) { return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix)); }
public void testParseIntFail() { try { UnsignedInts.parseUnsignedInt(Long.toString(1L << 32)); fail("Expected NumberFormatException"); } catch (NumberFormatException expected) { } }
public void testParseInt() { for (long a : UNSIGNED_INTS) { assertEquals((int) a, UnsignedInts.parseUnsignedInt(Long.toString(a))); } }
public void testParseIntWithRadix() { for (long a : UNSIGNED_INTS) { for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { assertEquals((int) a, UnsignedInts.parseUnsignedInt(Long.toString(a, radix), radix)); } } }
public void testParseIntWithRadixLimits() { // loops through all legal radix values. for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { // tests can successfully parse a number string with this radix. String maxAsString = Long.toString((1L << 32) - 1, radix); assertEquals(-1, UnsignedInts.parseUnsignedInt(maxAsString, radix)); try { // tests that we get exception whre an overflow would occur. long overflow = 1L << 32; String overflowAsString = Long.toString(overflow, radix); UnsignedInts.parseUnsignedInt(overflowAsString, radix); fail(); } catch (NumberFormatException expected) { } } }
/** * Returns the unsigned {@code int} value represented by the given string. * * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix: * * <ul> * <li>{@code 0x}<i>HexDigits</i> * <li>{@code 0X}<i>HexDigits</i> * <li>{@code #}<i>HexDigits</i> * <li>{@code 0}<i>OctalDigits</i> * </ul> * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @since 13.0 */ @CanIgnoreReturnValue public static int decode(String stringValue) { ParseRequest request = ParseRequest.fromString(stringValue); try { return parseUnsignedInt(request.rawValue, request.radix); } catch (NumberFormatException e) { NumberFormatException decodeException = new NumberFormatException("Error parsing value: " + stringValue); decodeException.initCause(e); throw decodeException; } }
public void testParseIntThrowsExceptionForInvalidRadix() { // Valid radix values are Character.MIN_RADIX to Character.MAX_RADIX, // inclusive. try { UnsignedInts.parseUnsignedInt("0", Character.MIN_RADIX - 1); fail(); } catch (NumberFormatException expected) { } try { UnsignedInts.parseUnsignedInt("0", Character.MAX_RADIX + 1); fail(); } catch (NumberFormatException expected) { } // The radix is used as an array index, so try a negative value. try { UnsignedInts.parseUnsignedInt("0", -1); fail(); } catch (NumberFormatException expected) { } }
/** * Returns the unsigned {@code int} value represented by the given string. * * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix: * * <ul> * <li>{@code 0x}<i>HexDigits</i> * <li>{@code 0X}<i>HexDigits</i> * <li>{@code #}<i>HexDigits</i> * <li>{@code 0}<i>OctalDigits</i> * </ul> * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @since 13.0 */ @CanIgnoreReturnValue public static int decode(String stringValue) { ParseRequest request = ParseRequest.fromString(stringValue); try { return parseUnsignedInt(request.rawValue, request.radix); } catch (NumberFormatException e) { NumberFormatException decodeException = new NumberFormatException("Error parsing value: " + stringValue); decodeException.initCause(e); throw decodeException; } }
/** * Returns the unsigned {@code int} value represented by the given string. * * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix: * * <ul> * <li>{@code 0x}<i>HexDigits</i> * <li>{@code 0X}<i>HexDigits</i> * <li>{@code #}<i>HexDigits</i> * <li>{@code 0}<i>OctalDigits</i> * </ul> * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @since 13.0 */ @CanIgnoreReturnValue public static int decode(String stringValue) { ParseRequest request = ParseRequest.fromString(stringValue); try { return parseUnsignedInt(request.rawValue, request.radix); } catch (NumberFormatException e) { NumberFormatException decodeException = new NumberFormatException("Error parsing value: " + stringValue); decodeException.initCause(e); throw decodeException; } }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Integer#parseInt(String)}) */ public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Integer#parseInt(String)}) */ public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Integer#parseInt(String)}) */ public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns the unsigned {@code int} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Integer#parseInt(String)}) */ public static int parseUnsignedInt(String s) { return parseUnsignedInt(s, 10); }
/** * Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed * as an unsigned {@code int} value in the specified radix. * * @throws NumberFormatException if the string does not contain a parsable unsigned {@code int} * value */ public static UnsignedInteger valueOf(String string, int radix) { return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix)); }
/** * Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed as * an unsigned {@code int} value in the specified radix. * * @throws NumberFormatException if the string does not contain a parsable unsigned {@code int} * value */ public static UnsignedInteger valueOf(String string, int radix) { return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix)); }