f4b6a3 / ulid-creator Goto Github PK
View Code? Open in Web Editor NEWA Java library for generating Universally Unique Lexicographically Sortable Identifiers (ULID)
License: MIT License
A Java library for generating Universally Unique Lexicographically Sortable Identifiers (ULID)
License: MIT License
New constructors:
public UlidFactory(Random random) { }
public UlidFactory(RandomGenerator randomGenerator) { }
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.
are you using any post java 8 features that make it hard to support java 8?
Objectives:
Ulid min = Ulid.MIN;
Ulid max = Ulid.MAX;
Ulid min = Ulid.min(time);
Ulid max = Ulid.max(time);
Methods to implement:
UlidStruct.toUuid4()
UlidStruct.toString4()
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
UnnecessaryParentheses
Tool: ErrorProne (JDK8)
File: src/main/java/com/github/f4b6a3/ulid/Ulid.java
Line: 544
Description: Unnecessary use of grouping parentheses
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.
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)?
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
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()
.
Add this line to MANIFEST.MF:
Automatic-Module-Name: com.github.f4b6a3.ulid
Methods to create:
UlidCreator.getUlid4()
;UlidCreator.getUlidString4()
;Methods to optimize:
UlidCreator.createString()
UlidConverter.toString()
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.
Keep monotonicity in case of small clock drift.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.