Package com.helixframework.id.ulid
Class UlidUtil
java.lang.Object
com.helixframework.id.ulid.UlidUtil
Utility for working with ULIDs.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two ULIDs lexicographically.static Stringfrom(byte[] bytes) Converts the supplied UUID bytes to a ULID.static StringConverts the supplied UUID to a ULID.static byte[]getEntropy(String ulid) Gets the entropy component of the ulid.static longgetTimestamp(String ulid) Gets the timestamp component of the ULID.static booleanChecks to see if the supplied string is valid ULID.static StringGenerates the next monotonic ULID from the supplied ULID.static Stringrandom()Generate a random ULID.static Stringrandom(long timestamp) Generate a random ULID with the specified timestamp component.static StringGenerates a random ULID using the specified randomness source.static StringGenerates a random ULID using the specified randomness source and timestamp component.strictlyNext(String ulid) Generates the next monotonic ULID from the supplied ULID.static UUIDConverts the ULID to UUID.static com.offbytwo.ulid.ULID.ValueTries to parse the supplied ULID.
-
Method Details
-
random
Generate a random ULID.- Returns:
- ulid
-
random
Generate a random ULID with the specified timestamp component.- Parameters:
timestamp- timestamp- Returns:
- ulid
-
random
Generates a random ULID using the specified randomness source.- Parameters:
rand- randomness source- Returns:
- ulid
-
random
Generates a random ULID using the specified randomness source and timestamp component.- Parameters:
rand- randomness sourcetimestamp- timestamp- Returns:
- ulid
-
tryParse
Tries to parse the supplied ULID.- Parameters:
ulid- ulid- Returns:
- parsed value or null if the supplied value is not a valid ULID
-
next
Generates the next monotonic ULID from the supplied ULID.This method will roll over the entropy portion in the event of an overflow.
- Parameters:
ulid- starting ulid- Returns:
- next monotonic ULID
-
strictlyNext
Generates the next monotonic ULID from the supplied ULID. If an overflow occurs this method will return empty instead of rolling.- Parameters:
ulid- ulid- Returns:
- next monotonic ULID
-
from
Converts the supplied UUID to a ULID.- Parameters:
uuid- uuid- Returns:
- ulid
-
from
Converts the supplied UUID bytes to a ULID.- Parameters:
bytes- uuid bytes- Returns:
- ulid
-
toUUID
Converts the ULID to UUID.- Parameters:
ulid- ulid- Returns:
- uuid
-
getTimestamp
Gets the timestamp component of the ULID.- Parameters:
ulid- ulid- Returns:
- timestamp
-
getEntropy
Gets the entropy component of the ulid.- Parameters:
ulid- ulid- Returns:
- entropy bytes
-
compareTo
Compares two ULIDs lexicographically.- Parameters:
ulid1- first ulidulid2- second ulid- Returns:
- 0 if the string is equal to the other string, < 0 if the string is lexicographically less than the other string, > 0 if the string is lexicographically greater than the other string (more characters)
-
isValid
Checks to see if the supplied string is valid ULID.- Parameters:
ulid- ulid- Returns:
trueif valid; otherwisefalse
-