dev
ZhouXY108 2024-03-14 23:16:08 +08:00
parent 8d9ccdb08e
commit dc9e0d1b53
1 changed files with 2 additions and 2 deletions

View File

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