Package org.miaixz.bus.core.data.id
Class ULID
java.lang.Object
org.miaixz.bus.core.data.id.ULID
- All Implemented Interfaces:
Serializable,Comparable<ULID>
ULID(Universally Unique Lexicographically Sortable Identifier)通用唯一词典分类标识符,特性:
- 与UUID的128位兼容性
- 每毫秒1.21e + 24个唯一ULID
- 按字典顺序(也就是字母顺序)排序
- 规范地编码为26个字符串,而不是UUID的36个字符
- 使用Crockford的base32获得更好的效率和可读性(每个字符5位)
- 不区分大小写
- 没有特殊字符(URL安全)
- 单调排序顺序(正确检测并处理相同的毫秒)
参考:https://github.com/zjcscut/framework-mesh/blob/master/ulid4j/src/main/java/cn/vlts/ulid/ULID.java
01AN4Z07BY 79KA1307SR9X4MV3
|----------| |----------------|
Timestamp Randomness
48bits 80bits
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanlong获取最低有效位(Least Significant Bit),64 bit(8 bytes)long获取最高有效位(Most Significant Bit),64 bit(8 bytes)byte[]获取ULID的随机数部分long获取ULID的时间戳部分inthashCode()自增ULIDnextMonotonic(long timestamp) 获取下一个有序的ULIDstatic ULIDof()创建一个新的ULID,使用当前系统时间戳和随机数static ULIDof(byte[] data) 从bytes解析ULIDstatic ULIDof(long timestamp) 创建一个新的ULID,使用指定系统时间戳和随机数static ULIDof(long timestamp, byte[] randomness) 创建一个新的ULID,使用指定系统时间戳和指定填充数static ULID创建一个新的ULID,使用指定系统时间戳和指定随机对象static ULID解析一个Crockford`s Base32的ULIDbyte[]toBytes()转为bytes值,16位,0-7为mostSignificantBits,8-15为leastSignificantBits转为JDK的UUIDtoString()toUUID()转为UUID
-
Constructor Details
-
ULID
构造- Parameters:
no128- 16位数字
-
-
Method Details
-
of
创建一个新的ULID,使用当前系统时间戳和随机数- Returns:
- ULID
-
of
创建一个新的ULID,使用指定系统时间戳和随机数- Parameters:
timestamp- 时间戳- Returns:
- ULID
-
of
创建一个新的ULID,使用指定系统时间戳和指定随机对象- Parameters:
timestamp- 时间戳random-Random- Returns:
- ULID
-
of
创建一个新的ULID,使用指定系统时间戳和指定填充数- Parameters:
timestamp- 时间戳randomness- 指定填充数- Returns:
- ULID
-
of
解析一个Crockford`s Base32的ULID- Parameters:
ulidString- Crockford`s Base32的ULID- Returns:
- ULID
-
of
从bytes解析ULID- Parameters:
data- bytes,16位,0-7为mostSignificantBits,8-15为leastSignificantBits- Returns:
- ULID
-
getMostSignificantBits
public long getMostSignificantBits()获取最高有效位(Most Significant Bit),64 bit(8 bytes)- Returns:
- 最高有效位(Most Significant Bit),64 bit(8 bytes)
-
getLeastSignificantBits
public long getLeastSignificantBits()获取最低有效位(Least Significant Bit),64 bit(8 bytes)- Returns:
- 最低有效位(Least Significant Bit),64 bit(8 bytes)
-
getTimestamp
public long getTimestamp()获取ULID的时间戳部分- Returns:
- 时间戳
-
getRandomness
public byte[] getRandomness()获取ULID的随机数部分- Returns:
- 随机数部分
-
increment
自增ULID- Returns:
- 返回自增ULID
-
nextMonotonic
获取下一个有序的ULID- Parameters:
timestamp- 时间戳- Returns:
- 如果给定时间戳与当前ULID相同,则返回自增ULID,否则返回一个新的ULID
-
toBytes
public byte[] toBytes()转为bytes值,16位,0-7为mostSignificantBits,8-15为leastSignificantBits- Returns:
- bytes值
-
toUUID
转为UUID- Returns:
- UUID
-
toJdkUUID
转为JDK的UUID- Returns:
- UUID
-
compareTo
- Specified by:
compareToin interfaceComparable<ULID>
-
equals
-
hashCode
public int hashCode() -
toString
-