diff --git a/Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java b/Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java index ab4e541..a97e349 100644 --- a/Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java +++ b/Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java @@ -25,15 +25,13 @@ public class DefaultIdGenerator implements IIdGenerator { throw new IdGeneratorException("BaseTime error."); } + if (options.WorkerIdBitLength <= 0) { + throw new IdGeneratorException("WorkerIdBitLength error.(range:[1, 21])"); + } if (options.SeqBitLength + options.WorkerIdBitLength > 22) { throw new IdGeneratorException("error:WorkerIdBitLength + SeqBitLength <= 22"); } - if (options.WorkerIdBitLength <= 0) - { - throw new IdGeneratorException("WorkerIdBitLength error.(range:[1, 21])"); - } - double maxWorkerIdNumber = Math.pow(2, options.WorkerIdBitLength) - 1; if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) { throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]");