All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rxyor.common.util.lang.SnowFlakeUtil Maven / Gradle / Ivy

There is a newer version: 1.0.14.17
Show newest version
package com.github.rxyor.common.util.lang;

import java.util.Objects;
import lombok.Getter;

/**
 *

* *

* * @author liuyang * @date 2019-05-21 Tue 14:31:00 * @since 1.0.0 */ public class SnowFlakeUtil { @Getter private static Long datacenterId = 0L; @Getter private static Long machineId = 0L; private static SnowFlake snowFlake; static { snowFlake = new SnowFlake(datacenterId, machineId); } public static void reset(Long datacenterId, Long machineId) { Objects.requireNonNull(datacenterId, "datacenterId can't be nul"); Objects.requireNonNull(machineId, "machineId can't be nul"); SnowFlakeUtil.datacenterId = datacenterId; SnowFlakeUtil.machineId = machineId; SnowFlakeUtil.snowFlake = new SnowFlake(datacenterId, machineId); } public static Long nextId() { return snowFlake.nextId(); } public static String nextStringId() { return Long.toString(snowFlake.nextId()); } public static String nextHexId() { return Long.toHexString(nextId()); } public static void main(String[] args) { for (int i = 0; i < (1 << 12); i++) { System.out.println(SnowFlakeUtil.nextHexId()); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy