- java.lang.Object
-
- com.github.f4b6a3.ulid.UlidCreator
-
public final class UlidCreator extends Object
A class that generates ULIDs.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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UlidgetHashUlid(long time, byte[] bytes)Returns a Hash ULID.static UlidgetHashUlid(long time, String string)Returns a Hash ULID.static UlidgetMonotonicUlid()Returns a Monotonic ULID.static UlidgetMonotonicUlid(long time)Returns a Monotonic ULID.static UlidgetUlid()Returns a ULID.static UlidgetUlid(long time)Returns a ULID.
-
-
-
Method Detail
-
getUlid
public static Ulid getUlid()
Returns a ULID.The random component is reset for each new ULID generated.
- Returns:
- a ULID
-
getUlid
public static Ulid getUlid(long time)
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
public static Ulid getMonotonicUlid()
Returns a Monotonic ULID.The random component is incremented for each new ULID generated in the same millisecond.
- Returns:
- a ULID
-
getMonotonicUlid
public static Ulid getMonotonicUlid(long time)
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
public static Ulid getHashUlid(long time, String string)
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
public static Ulid getHashUlid(long time, byte[] bytes)
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
-
-