HHH-18377 Renamed State record properties with addres 'last' prefix
This commit is contained in:
parent
6daec2e410
commit
3419f8f3ad
|
@ -42,23 +42,23 @@ public class UuidVersion6Strategy implements UUIDGenerationStrategy, UuidValueGe
|
|||
|
||||
}
|
||||
|
||||
private record State(long timestamp, int sequence) {
|
||||
private record State(long lastTimestamp, int lastSequence) {
|
||||
public State getNextState() {
|
||||
final long now = instantToTimestamp();
|
||||
if ( this.timestamp < now ) {
|
||||
if ( this.lastTimestamp < now ) {
|
||||
return new State(
|
||||
now,
|
||||
randomSequence()
|
||||
);
|
||||
}
|
||||
else if ( sequence == 0x3FFF ) {
|
||||
else if ( lastSequence == 0x3FFF ) {
|
||||
return new State(
|
||||
this.timestamp + 1,
|
||||
this.lastTimestamp + 1,
|
||||
randomSequence()
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new State( timestamp, sequence + 1 );
|
||||
return new State( lastTimestamp, lastSequence + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,15 +104,15 @@ public class UuidVersion6Strategy implements UUIDGenerationStrategy, UuidValueGe
|
|||
|
||||
return new UUID(
|
||||
// MSB bits 0-47 - most significant 32 bits of the 60-bit starting timestamp
|
||||
state.timestamp << 4 & 0xFFFF_FFFF_FFFF_0000L
|
||||
state.lastTimestamp << 4 & 0xFFFF_FFFF_FFFF_0000L
|
||||
// MSB bits 48-51 - version = 6
|
||||
| 0x6000L
|
||||
// MSB bits 52-63 - least significant 12 bits from the 60-bit starting timestamp
|
||||
| state.timestamp & 0x0FFFL,
|
||||
| state.lastTimestamp & 0x0FFFL,
|
||||
// LSB bits 0-1 - variant = 4
|
||||
0x8000_0000_0000_0000L
|
||||
// LSB bits 2-15 - clock sequence
|
||||
| ( state.sequence & 0x3FFFL ) << 48
|
||||
| ( state.lastSequence & 0x3FFFL ) << 48
|
||||
// LSB bits 16-63 - pseudorandom data, least significant bit of the first octet is set to 1
|
||||
| randomNode()
|
||||
);
|
||||
|
|
|
@ -44,31 +44,31 @@ public class UuidVersion7Strategy implements UUIDGenerationStrategy, UuidValueGe
|
|||
|
||||
}
|
||||
|
||||
public record State(Instant timestamp, int sequence) {
|
||||
public record State(Instant lastTimestamp, int lastSequence) {
|
||||
public long millis() {
|
||||
return timestamp.toEpochMilli();
|
||||
return lastTimestamp.toEpochMilli();
|
||||
}
|
||||
|
||||
public long nanos() {
|
||||
return (long) ( ( timestamp.getNano() % 1_000_000L ) * 0.004096 );
|
||||
return (long) ( ( lastTimestamp.getNano() % 1_000_000L ) * 0.004096 );
|
||||
}
|
||||
|
||||
public State getNextState() {
|
||||
final Instant now = Instant.now();
|
||||
if ( timestamp.toEpochMilli() < now.toEpochMilli() ) {
|
||||
if ( lastTimestamp.toEpochMilli() < now.toEpochMilli() ) {
|
||||
return new State(
|
||||
now.truncatedTo( MILLIS ),
|
||||
randomSequence()
|
||||
);
|
||||
}
|
||||
else if ( sequence == 0x3FFF ) {
|
||||
else if ( lastSequence == 0x3FFF ) {
|
||||
return new State(
|
||||
timestamp.plusMillis( 1 ),
|
||||
lastTimestamp.plusMillis( 1 ),
|
||||
Holder.numberGenerator.nextInt( 1 << 14 )
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new State( timestamp, sequence + 1 );
|
||||
return new State( lastTimestamp, lastSequence + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class UuidVersion7Strategy implements UUIDGenerationStrategy, UuidValueGe
|
|||
// LSB bits 0-1 - variant = 4
|
||||
0x8000_0000_0000_0000L
|
||||
// LSB bits 2-15 - counter
|
||||
| ( state.sequence & 0x3FFFL ) << 48
|
||||
| ( state.lastSequence & 0x3FFFL ) << 48
|
||||
// LSB bits 16-63 - pseudorandom data
|
||||
| randomNode()
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue