@CompileStatic class CombUuidShortPrefixUtils extends Object
Various helper methods for working with random (version 4, variant 2) COMB UUIDs with short prefix (https://github.com/f4b6a3/uuid-creator/wiki/2.3.-Short-Prefix-COMB).
Some implementation notes aboutSecureRandom
usage:
uuid-creator
caches random function instances. It looks like this is not necessary, as suggested by
https://stackoverflow.com/questions/27622625/securerandom-with-nativeprng-vs-sha1prng/27638413#27638413 . Therefore, we are not using uuid-creator's new DefaultRandomFunction()
, but
rather plain new SecureRandom()
. This should not affect performance, and should increase randomness.
new SecureRandom()
should be more than enough to get appropriate randomness in platform independent way as suggested by
https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/
new DefaultRandomFunction()
at the application service level as a singleton, and provide it here as a parameter.
Type | Name and description |
---|---|
static Integer |
IN_FUTURE_MINUTES_BOUND_DEFAULT |
static Integer |
IN_PAST_MINUTES_BOUND_DEFAULT |
static Integer |
ONE_MINUTE_MILLIS |
static Integer |
THE_64_K |
Constructor and description |
---|
CombUuidShortPrefixUtils() |
Type Params | Return Type | Name and description |
---|---|---|
|
static boolean |
checkIfCombShortPrefixIsBounded(UUID uuid, Clock clock, Integer inPastMinutesBound, Integer inFutureMinutesBound) Checks if provided UUID instance is time-bounded as expected. |
|
static boolean |
checkIfCombShortPrefixStringIsBounded(String uuidStringToCheck, Clock clock, Integer inPastMinutesBound, Integer inFutureMinutesBound) Checks if provided UUID string is time-bounded as expected. |
|
static String |
deriveCombShortPrefixHexaString(Clock clock) Derives COMB UUID short prefix as hexa string for the current time or for provided clock parameter. |
|
static UUID |
makeCombShortPrefix(Clock clock) Produces COMB UUID with short prefix for the current time or for provided clock parameter. |
Checks if provided UUID instance is time-bounded as expected.
Method assumes that provided UUID is COMB UUID with short prefix. Otherwise it will returnfalse
.
By default time-bounds are checked against the current time. Base time can be changed via clock
parameter.
By default, time bounds are 10 minutes in the past and 10 minutes in the future. This can be changed via inPastMinutesBound
and inFutureMinutesBound
parameters.
Method will return false
if provided uuid
instance is null
or if it is not random UUID (version 4, variant 2).
Checks if provided UUID string is time-bounded as expected.
Method will returnfalse
for null
and empty strings, and for any other input that cannot be parsed with UUID.fromString(String)
.
All other parameters are handled in the same was as in checkIfCombShortPrefixIsBounded(java.util.UUID).
Derives COMB UUID short prefix as hexa string for the current time or for provided clock
parameter.
Groovy Documentation