Creates a HashCode from a hexadecimal (base 16) encoded string. The string must be at least 2 characters long, and contain only valid, lower-cased hexadecimal characters. This method accepts the exact format generated by #toString. If you require more lenient {@code base
(String string)
| 356 | |
| 357 | |
| 358 | public static HashCode fromString(String string) { |
| 359 | checkArgument(string.length() >= 2, "input string (%s) must have at least 2 characters", string); |
| 360 | checkArgument(string.length() % 2 == 0, "input string (%s) must have an even number of characters", string); |
| 361 | byte[] bytes = new byte[string.length() / 2]; |
| 362 | for (int i = 0; i < string.length(); i += 2) { |
| 363 | int ch1 = decode(string.charAt(i)) << 4; |
| 364 | int ch2 = decode(string.charAt(i + 1)); |
| 365 | bytes[i / 2] = (byte) (ch1 + ch2); |
| 366 | } |
| 367 | return fromBytesNoCopy(bytes); |
| 368 | } |
| 369 | |
| 370 | private static int decode(char ch) { |
| 371 | if (ch >= '0' && ch <= '9') { |
nothing calls this directly
no test coverage detected