修改约束条件
This commit is contained in:
@@ -25,12 +25,13 @@ public class IdGeneratorOptions {
|
||||
/**
|
||||
* 机器码,必须由外部系统设置
|
||||
* 与 WorkerIdBitLength 有关系
|
||||
* (short类型,最大值32766,如果有更高要求,请修改数据类型,或联系作者)
|
||||
*/
|
||||
public short WorkerId = 0;
|
||||
|
||||
/**
|
||||
* 机器码位长
|
||||
* 范围:2-21(要求:序列数位长+机器码位长不超过22)。
|
||||
* 范围:1-21(要求:序列数位长+机器码位长不超过22)。
|
||||
* 建议范围:6-12。
|
||||
*/
|
||||
public byte WorkerIdBitLength = 6;
|
||||
@@ -50,7 +51,7 @@ public class IdGeneratorOptions {
|
||||
|
||||
/**
|
||||
* 最小序列数(含)
|
||||
* 默认5,不小于1,不大于MaxSeqNumber-1
|
||||
* 默认5,不小于1,不大于MaxSeqNumber
|
||||
*/
|
||||
public short MinSeqNumber = 5;
|
||||
|
||||
|
||||
@@ -23,24 +23,21 @@ public class SnowWorkerM1 implements ISnowWorker {
|
||||
|
||||
/**
|
||||
* 机器码位长
|
||||
* (机器码+序列数<=22位)
|
||||
*/
|
||||
protected final byte WorkerIdBitLength;
|
||||
|
||||
/**
|
||||
* 自增序列数位长
|
||||
* (机器码+序列数<=22位)
|
||||
*/
|
||||
protected final byte SeqBitLength;
|
||||
|
||||
/**
|
||||
* 最大序列数(含此值)
|
||||
* 超过最大值,就会从MinSeqNumber开始
|
||||
* 最大序列数(含)
|
||||
*/
|
||||
protected final int MaxSeqNumber;
|
||||
|
||||
/**
|
||||
* 最小序列数(含此值)
|
||||
* 最小序列数(含)
|
||||
*/
|
||||
protected final short MinSeqNumber;
|
||||
|
||||
@@ -64,7 +61,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);
|
||||
MaxSeqNumber = options.MaxSeqNumber > 0 ? options.MaxSeqNumber : (int) Math.pow(2, SeqBitLength) - 1;
|
||||
MinSeqNumber = options.MinSeqNumber;
|
||||
TopOverCostCount = options.TopOverCostCount;
|
||||
BaseTime = options.BaseTime != 0 ? options.BaseTime : 1582136402000L;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class DefaultIdGenerator implements IIdGenerator {
|
||||
}
|
||||
|
||||
double maxWorkerIdNumber = Math.pow(2, options.WorkerIdBitLength) - 1;
|
||||
if (options.WorkerId < 1 || options.WorkerId > maxWorkerIdNumber) {
|
||||
if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) {
|
||||
throw new IdGeneratorException("WorkerId error. (range:[1, " + maxWorkerIdNumber + "]");
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ public class DefaultIdGenerator implements IIdGenerator {
|
||||
throw new IdGeneratorException("MaxSeqNumber error. (range:[1, " + maxSeqNumber + "]");
|
||||
}
|
||||
|
||||
double maxValue = maxSeqNumber - 2;
|
||||
if (options.MinSeqNumber < 5 || options.MinSeqNumber > maxValue) {
|
||||
throw new IdGeneratorException("MinSeqNumber error. (range:[5, " + maxValue + "]");
|
||||
double maxValue = maxSeqNumber;
|
||||
if (options.MinSeqNumber < 1 || options.MinSeqNumber > maxValue) {
|
||||
throw new IdGeneratorException("MinSeqNumber error. (range:[1, " + maxValue + "]");
|
||||
}
|
||||
|
||||
switch (options.Method) {
|
||||
|
||||
Reference in New Issue
Block a user