io.github.dengchen2020.id.IdHelper Maven / Gradle / Ivy
package io.github.dengchen2020.id;
import io.github.dengchen2020.id.exception.IdGeneratorException;
import io.github.dengchen2020.id.snowflake.SnowflakeIdGeneratorOptions;
import io.github.dengchen2020.id.snowflake.SnowflakeIdGenerator;
/**
* id生成辅助工具
* @author dengchen
* @since 2024/7/1
*/
public class IdHelper {
private static IdGenerator idGenInstance = null;
public static IdGenerator getIdGenInstance() {
return idGenInstance;
}
/**
* 设置参数,程序仅初始化时执行一次
*/
public static void setIdGenerator(IdGenerator generator) throws IdGeneratorException {
if(idGenInstance == null) idGenInstance = generator;
}
/**
* 生成新的Id
* 调用本方法前,请确保调用了 setIdGenerator 方法做初始化。
*
* @return id
*/
public static long nextId() throws IdGeneratorException {
return idGenInstance.newLong();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy