356 * {@code 357 * UUID = <time_low> "-" <time_mid> "-" 358 * <time_high_and_version> "-" 359 * <variant_and_sequence> "-" 360 * <node> 361 * time_low = 4*<hexOctet> 362 * time_mid = 2*<hexOctet> 363 * time_high_and_version = 2*<hexOctet> 364 * variant_and_sequence = 2*<hexOctet> 365 * node = 6*<hexOctet> 366 * hexOctet = <hexDigit><hexDigit> 367 * hexDigit = 368 * "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" 369 * | "a" | "b" | "c" | "d" | "e" | "f" 370 * | "A" | "B" | "C" | "D" | "E" | "F" 371 * }</pre></blockquote> 372 * 373 * @return A string representation of this {@code UUID} 374 */ 375 public String toString() { 376 return (digits(mostSigBits >> 32, 8) + "-" + 377 digits(mostSigBits >> 16, 4) + "-" + 378 digits(mostSigBits, 4) + "-" + 379 digits(leastSigBits >> 48, 4) + "-" + 380 digits(leastSigBits, 12)); 381 } 382 383 /** Returns val represented by the specified number of hex digits. */ 384 private static String digits(long val, int digits) { 385 long hi = 1L << (digits * 4); 386 return Long.toHexString(hi | (val & (hi - 1))).substring(1); 387 } 388 389 /** 390 * Returns a hash code for this {@code UUID}. 391 * 392 * @return A hash code value for this {@code UUID} 393 */ 394 public int hashCode() { 395 long hilo = mostSigBits ^ leastSigBits; 396 return ((int)(hilo >> 32)) ^ (int) hilo; 397 } 398 399 /** 400 * Compares this object to the specified object. The result is {@code 401 * true} if and only if the argument is not {@code null}, is a {@code UUID} 402 * object, has the same variant, and contains the same value, bit for bit, 403 * as this {@code UUID}. 404 * 405 * @param obj 406 * The object to be compared | 356 * {@code 357 * UUID = <time_low> "-" <time_mid> "-" 358 * <time_high_and_version> "-" 359 * <variant_and_sequence> "-" 360 * <node> 361 * time_low = 4*<hexOctet> 362 * time_mid = 2*<hexOctet> 363 * time_high_and_version = 2*<hexOctet> 364 * variant_and_sequence = 2*<hexOctet> 365 * node = 6*<hexOctet> 366 * hexOctet = <hexDigit><hexDigit> 367 * hexDigit = 368 * "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" 369 * | "a" | "b" | "c" | "d" | "e" | "f" 370 * | "A" | "B" | "C" | "D" | "E" | "F" 371 * }</pre></blockquote> 372 * 373 * @return A string representation of this {@code UUID} 374 */ 375 public String toString() { 376 return Long.toHexString((mostSigBits >>> 32) & 0xFFFFFFFFL, 8) + '-' 377 + Long.toHexString((mostSigBits >>> 16) & 0xFFFFL, 4) + '-' 378 + Long.toHexString( mostSigBits & 0xFFFFL, 4) + '-' 379 + Long.toHexString((leastSigBits >>> 48) & 0xFFFFL, 4) + '-' 380 + Long.toHexString( leastSigBits & 0xFFFFFFFFFFFFL, 12); 381 } 382 383 /** 384 * Returns a hash code for this {@code UUID}. 385 * 386 * @return A hash code value for this {@code UUID} 387 */ 388 public int hashCode() { 389 long hilo = mostSigBits ^ leastSigBits; 390 return ((int)(hilo >> 32)) ^ (int) hilo; 391 } 392 393 /** 394 * Compares this object to the specified object. The result is {@code 395 * true} if and only if the argument is not {@code null}, is a {@code UUID} 396 * object, has the same variant, and contains the same value, bit for bit, 397 * as this {@code UUID}. 398 * 399 * @param obj 400 * The object to be compared |