Browse Source

auto commit

tags/v1.0.0
zhouzj 4 years ago
parent
commit
eec32633d7
1 changed files with 3 additions and 5 deletions
  1. +3
    -5
      Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java

+ 3
- 5
Java/source/src/main/java/com/yitter/idgen/DefaultIdGenerator.java View File

@@ -25,15 +25,13 @@ public class DefaultIdGenerator implements IIdGenerator {
throw new IdGeneratorException("BaseTime error."); throw new IdGeneratorException("BaseTime error.");
} }
if (options.WorkerIdBitLength <= 0) {
throw new IdGeneratorException("WorkerIdBitLength error.(range:[1, 21])");
}
if (options.SeqBitLength + options.WorkerIdBitLength > 22) { if (options.SeqBitLength + options.WorkerIdBitLength > 22) {
throw new IdGeneratorException("error:WorkerIdBitLength + SeqBitLength <= 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; double maxWorkerIdNumber = Math.pow(2, options.WorkerIdBitLength) - 1;
if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) { if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) {
throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]"); throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]");


Loading…
Cancel
Save