public final class UlidCreator extends Object
Both types of ULID can be easily created by this generator, i.e. monotonic and non-monotonic.
In addition, a "non-standard" hash-based ULID can also be generated, in which the random component is replaced with the first 10 bytes of an SHA-256 hash.
| 限定符和类型 | 方法和说明 |
|---|---|
static Ulid |
getHashUlid(long time,
byte[] bytes)
Returns a Hash ULID.
|
static Ulid |
getHashUlid(long time,
String string)
Returns a Hash ULID.
|
static Ulid |
getMonotonicUlid()
Returns a Monotonic ULID.
|
static Ulid |
getMonotonicUlid(long time)
Returns a Monotonic ULID.
|
static Ulid |
getUlid()
Returns a ULID.
|
static Ulid |
getUlid(long time)
Returns a ULID.
|
public static Ulid getUlid()
The random component is reset for each new ULID generated.
public static Ulid getUlid(long time)
The random component is reset for each new ULID generated.
time - the current time in milliseconds, measured from the UNIX epoch of
1970-01-01T00:00Z (UTC)public static Ulid getMonotonicUlid()
The random component is incremented for each new ULID generated in the same millisecond.
public static Ulid getMonotonicUlid(long time)
The random component is incremented for each new ULID generated in the same millisecond.
time - the current time in milliseconds, measured from the UNIX epoch of
1970-01-01T00:00Z (UTC)public static Ulid getHashUlid(long time, String string)
The random component is replaced with the first 10 bytes of an SHA-256 hash.
It always returns the same ULID for a specific pair of time and
string.
Usage example:
long time = file.getCreatedAt();
String name = file.getFileName();
Ulid ulid = UlidCreator.getHashUlid(time, name);
time - the time in milliseconds, measured from the UNIX epoch of
1970-01-01T00:00Z (UTC)string - a string to be hashed using SHA-256 algorithm.public static Ulid getHashUlid(long time, byte[] bytes)
The random component is replaced with the first 10 bytes of an SHA-256 hash.
It always returns the same ULID for a specific pair of time and
bytes.
Usage example:
long time = file.getCreatedAt();
byte[] bytes = file.getFileBinary();
Ulid ulid = UlidCreator.getHashUlid(time, bytes);
time - the time in milliseconds, measured from the UNIX epoch of
1970-01-01T00:00Z (UTC)bytes - a byte array to be hashed using SHA-256 algorithm.Copyright © 2025 fossc. All rights reserved.