com.blr19c.common.code.SnowflakeIdUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
The blr19c-common library contains utility classes, Map/Stream implementation, sending enterprise
WeChat, IP/ip address acquisition, mybatis-plus separation implementation, and so on.
package com.blr19c.common.code;
/**
* 生成雪花id
*
* @author blr
*/
public abstract class SnowflakeIdUtils {
private static final SnowflakeIdUtils DEFAULT_INSTANCE = getInstance(1);
public static SnowflakeIdUtils getInstance() {
return DEFAULT_INSTANCE;
}
public static SnowflakeIdUtils getInstance(long workerId) {
return new Snowflake(1623896691873L, workerId);
}
/**
* @param epoch 开始时间戳
* @param workerIdBits workerId占用位数
* @param sequenceBits 序列号占用的位数
* @param workerId 工作空间id
*/
public static SnowflakeIdUtils getInstance(long epoch, long workerIdBits, long sequenceBits, long workerId) {
return new Snowflake(epoch, workerIdBits, sequenceBits, workerId);
}
public static long defaultNextId() {
return getInstance().getId();
}
public abstract long getId();
public abstract long getWorkerId();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy