From dc9e0d1b53b3502a02093d5daca23f6e61413f81 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 14 Mar 2024 23:16:08 +0800 Subject: [PATCH] fix bug. --- .../xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java b/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java index 2e74309..7ed3888 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/SnowflakeIdGenerator.java @@ -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);