ЛР 3: масштабирование и отказоустойчивость API
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.example.mtusi_messenger.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record MessageKey(Instant createdAt, UUID id)
|
||||
implements Comparable<MessageKey> {
|
||||
|
||||
private static int compareUuidV7(UUID a, UUID b) {
|
||||
int result = Long.compareUnsigned(
|
||||
a.getMostSignificantBits(),
|
||||
b.getMostSignificantBits()
|
||||
);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return Long.compareUnsigned(
|
||||
a.getLeastSignificantBits(),
|
||||
b.getLeastSignificantBits()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MessageKey other) {
|
||||
int result = createdAt.compareTo(other.createdAt);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return compareUuidV7(id, other.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user