JAVA-15621, Potential issue in "Guide to UUID in Java" article. (#13271)

* JAVA-15621, Potential issue in "Guide to UUID in Java" article.

* JAVA-15621, Keep the raw strings in the article to make it easy for users to understand.

* JAVA-15621, Keep the raw strings in the article to make it easy for users to understand.

Co-authored-by: jogra <joseph.sterling.grah@miles.no>
This commit is contained in:
jsgrah-spring 2023-01-16 18:37:14 +01:00 committed by GitHub
parent 18787b33c5
commit c217f7e95c
1 changed files with 7 additions and 7 deletions

View File

@ -27,17 +27,17 @@ public final class UUIDGenerator {
private static long get64LeastSignificantBitsForVersion1() {
final long random63BitLong = new Random().nextLong() & 0x3FFFFFFFFFFFFFFFL;
final long variant3BitFlag = 0x8000000000000000L;
return random63BitLong + variant3BitFlag;
long variant3BitFlag = 0x8000000000000000L;
return random63BitLong | variant3BitFlag;
}
private static long get64MostSignificantBitsForVersion1() {
final long timeForUuidIn100Nanos = System.currentTimeMillis();
final long time_low = (timeForUuidIn100Nanos & 0x0000_0000_FFFF_FFFFL) << 32;
final long time_mid = ((timeForUuidIn100Nanos >> 32) & 0xFFFF) << 16;
final long currentTimeMillis = System.currentTimeMillis();
final long time_low = (currentTimeMillis & 0x0000_0000_FFFF_FFFFL) << 32;
final long time_mid = ((currentTimeMillis >> 32) & 0xFFFF) << 16;
final long version = 1 << 12;
final long time_hi = ((timeForUuidIn100Nanos >> 48) & 0x0FFF);
return time_low + time_mid + version + time_hi;
final long time_high = ((currentTimeMillis >> 48) & 0x0FFF);
return time_low | time_mid | version | time_high;
}
/**