Giter Site home page Giter Site logo

f4b6a3 / ulid-creator Goto Github PK

View Code? Open in Web Editor NEW
284.0 4.0 30.0 362 KB

A Java library for generating Universally Unique Lexicographically Sortable Identifiers (ULID)

License: MIT License

Java 98.93% Shell 0.61% Batchfile 0.46%
ulid guid uuid id-generator unique-id guid-generator uuid-generator java id identifier

ulid-creator's People

Contributors

dependabot[bot] avatar fabiolimace avatar moznion avatar sollecitom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ulid-creator's Issues

ULID from Timestamp and String?

Hi,

Is there any way to create an ULID from a Timestamp and a String (that gets "hashed", to fit as part of the ULID) ?

e.g.

UlidCreator.getUlid(long time,  String originalId)

So that when calling this would return always the same ULID?

Thank you.

MonotonicUlid vs Ulid

Can you please tell me the use cases where a "non-monotonic" Ulid should be preferred over a "monotonic" Ulid? I expected that the generation of a MonotonicUlid is much slower than a non-monotonic Ulid, but according to the benchmark, MonotonicUlid are much faster than non-monotonic Ulids created by UlidCreator.getUlid().

Ulid_fast                              thrpt    5  34523,147 ± 1022,114  ops/ms (9.98)
Ulid_fast_toString                     thrpt    5  19161,375 ±  662,563  ops/ms
-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
UlidCreator_getUlid                    thrpt    5   4276,614 ±   11,069  ops/ms (1.23)
UlidCreator_getUlid_toString           thrpt    5   3645,088 ±   85,478  ops/ms
-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
UlidCreator_getMonotonicUlid           thrpt    5  32921,698 ± 1286,983  ops/ms (9.51)
UlidCreator_getMonotonicUlid_toString  thrpt    5  18541,252 ±  710,281  ops/ms

ArrayIndexOutOfBoundsException on input with multiple bytes for a character

When using

Ulid.from(String)

it fails with

java.lang.ArrayIndexOutOfBoundsException: Index 3617 out of bounds for length 256
	at com.github.f4b6a3.ulid.Ulid.isValidCharArray(Ulid.java:801)
	at com.github.f4b6a3.ulid.Ulid.toCharArray(Ulid.java:776)
	at com.github.f4b6a3.ulid.Ulid.from(Ulid.java:325)

when the input string contains characters represented by more than 1 byte - in this example 3617. I had a string of length 26 java char however some of them are 2 bytes, rather than 1 (java char type is 2B). I'd expect the library to handle the input validity correctly and consistently throw IllegalArgumentException on invalid input.

breaking changes in 3.0.1

Hi,

I have updated to 3.0.1 and it seems there are breaking changes:

//before:
UlidCreator.getUlidString();
//now:
UlidCreator.getUlid().toString();
UlidCreator.getUlid().toLowerCase(); // this is nice! thanks!

The package com.github.f4b6a3.ulid.util with UlidUtil does not exist anymore:

// before
UlidUtil.extractInstant(ulid).atZone(ZoneId.systemDefault());
// now
Instant.ofEpochMilli(Ulid.from(ulid).getTime()).atZone(ZoneId.systemDefault());

I think, the above code are ok.

Is there anywhere a changelog in the repo (at least for breaking api changes)?

Add simple format methods

Goal 1: produce formatted ULID.

String format = "K%S";
String key = Ulid.fast().format(format); // key: K01H62SKJ3KYWH89R6GG6PNKHKD
String format = "DOC_%S.pdf";
String filename = Ulid.fast().format(format); // filename: DOC_01H62SKJ3KYWH89R6GG6PNKHKD.pdf

Goal 2: parse formatted ULID.

String format = "K%S";
String key = "K01H62SKJ3KYWH89R6GG6PNKHKD";
Ulid ulid = Ulid.unformat(key, format); // ulid: 01H62SKJ3KYWH89R6GG6PNKHKD
String format = "DOC_%S.pdf";
String filename = "DOC_01H62SKJ3KYWH89R6GG6PNKHKD.pdf";
Ulid ulid = Ulid.unformat(filename, format); // ulid: 01H62SKJ3KYWH89R6GG6PNKHKD

Add a fast method to generate identifiers

Implement a convenience method to generate quick ULIDs.

Ulid ulid = Ulid.fast();

SplittableRandom will be employed by this method.

Security-sensitive applications that require a cryptographically strong pseudo-random generator should continue to use UlidCreator.getUlid().

Remove the overrun exception

The overrun UlidCreatorException is unnecessary.

It's extremelly unlikely that an instance of UlidSpecCreator will be able to generate 1152921504606846976 (2^60) ULIDs within a single millisecond.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.