f4b6a3 / uuid-creator

UUID Creator is a Java library for generating Universally Unique Identifiers.
MIT License
432 stars 44 forks source link

extractInstant() from Comb-String #35

Closed nimo23 closed 3 years ago

nimo23 commented 3 years ago

One question:

How can I get the Instant from a comb which comes from a String?

var combString = UuidCreator.getPrefixComb().toString();

There is a UuidUtil.extractInstant(), UlidUtil.extractInstant(), but no CombUtil.extractInstant().

fabiolimace commented 3 years ago

When COMB generators were implemented, the extraction methods were left to be implemented in the future. I wasn't sure if anyone was going to need it.

I just released version 3.5.0. The following methods are now available:

No extraction method was implemented for Short Prefix COMBs and Short Suffix COMBs.

Now to extract the Instant you can do this:

String combString = UuidCreator.getPrefixComb().toString();

StringCodec codec = new StringCodec(); // initialize the canonical string codec
UUID comb = codec.decode(combString); // decode the comb string
Instant instant = CombUtil.extractPrefixInstant(comb); // extract the instant