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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic UlidgetHashUlid(long time, byte[] bytes) Returns a Hash ULID.static UlidgetHashUlid(long time, String string) Returns a Hash ULID.static UlidReturns a Monotonic ULID.static UlidgetMonotonicUlid(long time) Returns a Monotonic ULID.static UlidgetUlid()Returns a ULID.static UlidgetUlid(long time) Returns a ULID.
-
Method Details
-
getUlid
Returns a ULID.The random component is reset for each new ULID generated.
- Returns:
- a ULID
-
getUlid
Returns a ULID.The random component is reset for each new ULID generated.
- Parameters:
time- the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
- a ULID
-
getMonotonicUlid
Returns a Monotonic ULID.The random component is incremented for each new ULID generated in the same millisecond.
- Returns:
- a ULID
-
getMonotonicUlid
Returns a Monotonic ULID.The random component is incremented for each new ULID generated in the same millisecond.
- Parameters:
time- the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
- a ULID
-
getHashUlid
Returns a Hash ULID.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
timeandstring.Usage example:
long time = file.getCreatedAt(); String name = file.getFileName(); Ulid ulid = UlidCreator.getHashUlid(time, name);- Parameters:
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.- Returns:
- a ULID
- Since:
- 5.2.0
-
getHashUlid
Returns a Hash ULID.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
timeandbytes.Usage example:
long time = file.getCreatedAt(); byte[] bytes = file.getFileBinary(); Ulid ulid = UlidCreator.getHashUlid(time, bytes);- Parameters:
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.- Returns:
- a ULID
- Since:
- 5.2.0
-