Esempio n. 1
0
 public static HashCode fromString(final String string) {
   Preconditions.checkArgument(
       string.length() >= 2, "input string (%s) must have at least 2 characters", string);
   Preconditions.checkArgument(
       string.length() % 2 == 0,
       "input string (%s) must have an even number of characters",
       string);
   final byte[] bytes = new byte[string.length() / 2];
   for (int i = 0; i < string.length(); i += 2) {
     final int ch1 = decode(string.charAt(i)) << 4;
     final int ch2 = decode(string.charAt(i + 1));
     bytes[i / 2] = (byte) (ch1 + ch2);
   }
   return fromBytesNoCopy(bytes);
 }
Esempio n. 2
0
 public static HashCode fromBytes(final byte[] bytes) {
   Preconditions.checkArgument(
       bytes.length >= 1, (Object) "A HashCode must contain at least 1 byte.");
   return fromBytesNoCopy(bytes.clone());
 }