From c08ddab81312e752c655789dc7957caaabdc0db0 Mon Sep 17 00:00:00 2001 From: yitter Date: Tue, 30 Mar 2021 11:42:23 +0800 Subject: [PATCH] auto commit --- Java/README.md | 9 +++++---- Java/source/pom.xml | 2 +- .../com/github/yitter/contract/IdGeneratorOptions.java | 2 +- .../main/java/com/github/yitter/core/SnowWorkerM1.java | 2 +- .../java/com/github/yitter/idgen/DefaultIdGenerator.java | 8 +++----- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Java/README.md b/Java/README.md index 51a6740..e914e60 100644 --- a/Java/README.md +++ b/Java/README.md @@ -8,22 +8,23 @@ JDK 1.8+ com.github.yitter yitter-idgenerator - 1.0.2 + 1.0.3 ``` ## 调用示例 ``` -// 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置) +// 全局初始化设置WorkerId,默认最大2^16-1,可通过调整 WorkerIdBitLength 增加最大值 IdGeneratorOptions options = new IdGeneratorOptions(); options.WorkerId = 1; YitIdHelper.setIdGenerator(options); +// 以上初始化过程全局只需一次,且必须最先设置 -// 初始化以后,就可以在需要的地方调用方法生成ID。 +// 初始化以后,即可在需要生成ID的地方,调用以下方法。 long newId = YitIdHelper.nextId(); ``` -如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。 +如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。 ## options 默认值及说明 diff --git a/Java/source/pom.xml b/Java/source/pom.xml index 3d80c29..6fb9e8e 100644 --- a/Java/source/pom.xml +++ b/Java/source/pom.xml @@ -6,7 +6,7 @@ com.github.yitter yitter-idgenerator - 1.0.3-SNAPSHOT + 1.0.4-SNAPSHOT jar yitter-idgenerator diff --git a/Java/source/src/main/java/com/github/yitter/contract/IdGeneratorOptions.java b/Java/source/src/main/java/com/github/yitter/contract/IdGeneratorOptions.java index 029b482..8c56dae 100644 --- a/Java/source/src/main/java/com/github/yitter/contract/IdGeneratorOptions.java +++ b/Java/source/src/main/java/com/github/yitter/contract/IdGeneratorOptions.java @@ -51,7 +51,7 @@ public class IdGeneratorOptions { /** * 鏈灏忓簭鍒楁暟锛堝惈锛 - * 榛樿5锛屼笉灏忎簬1锛屼笉澶т簬MaxSeqNumber + * 榛樿5锛屼笉灏忎簬5锛屼笉澶т簬MaxSeqNumber */ public short MinSeqNumber = 5; diff --git a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java index a6c8c85..be45ebc 100644 --- a/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java +++ b/Java/source/src/main/java/com/github/yitter/core/SnowWorkerM1.java @@ -63,7 +63,7 @@ public class SnowWorkerM1 implements ISnowWorker { WorkerId = options.WorkerId; WorkerIdBitLength = options.WorkerIdBitLength == 0 ? 6 : options.WorkerIdBitLength; SeqBitLength = options.SeqBitLength == 0 ? 6 : options.SeqBitLength; - MaxSeqNumber = options.MaxSeqNumber > 0 ? options.MaxSeqNumber : (int) Math.pow(2, SeqBitLength) - 1; + MaxSeqNumber = options.MaxSeqNumber > 0 ? options.MaxSeqNumber : (1 << SeqBitLength) - 1; MinSeqNumber = options.MinSeqNumber; TopOverCostCount = options.TopOverCostCount; BaseTime = options.BaseTime != 0 ? options.BaseTime : 1582136402000L; diff --git a/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java b/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java index 583f205..a293a02 100644 --- a/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java +++ b/Java/source/src/main/java/com/github/yitter/idgen/DefaultIdGenerator.java @@ -47,17 +47,15 @@ public class DefaultIdGenerator implements IIdGenerator { } int maxValue = maxSeqNumber; - if (options.MinSeqNumber < 1 || options.MinSeqNumber > maxValue) { - throw new IdGeneratorException("MinSeqNumber error. (range:[1, " + maxValue + "]"); + if (options.MinSeqNumber < 5 || options.MinSeqNumber > maxValue) { + throw new IdGeneratorException("MinSeqNumber error. (range:[5, " + maxValue + "]"); } switch (options.Method) { - case 1: - _SnowWorker = new SnowWorkerM1(options); - break; case 2: _SnowWorker = new SnowWorkerM2(options); break; + case 1: default: _SnowWorker = new SnowWorkerM1(options); break;