dev
ZhouXY108 2024-03-19 08:29:47 +08:00
parent 39fe3d30d1
commit f0cc49d06c
1 changed files with 2 additions and 2 deletions

View File

@ -64,9 +64,9 @@ public class SnowflakeIdGenerator {
* @param datacenterId ID (0~31)
*/
public SnowflakeIdGenerator(final long workerId, final long datacenterId) {
Preconditions.checkArgument((workerId <= MAX_WORKER_ID || workerId >= 0),
Preconditions.checkArgument((workerId <= MAX_WORKER_ID && workerId >= 0),
"WorkerId can't be greater than %s or less than 0.", MAX_WORKER_ID);
Preconditions.checkArgument((datacenterId <= MAX_DATACENTER_ID || datacenterId >= 0),
Preconditions.checkArgument((datacenterId <= MAX_DATACENTER_ID && datacenterId >= 0),
"DatacenterId can't be greater than %s or less than 0.", MAX_DATACENTER_ID);
this.datacenterIdAndWorkerId
= (datacenterId << DATACENTER_ID_SHIFT) | (workerId << WORKER_ID_SHIFT);