spec
spec copied to clipboard
Add Java implementation (ulid-creator)
This PR adds a library that implements the ULID spec.
ULID Creator
ULID Creator is a Java library that generates ULIDs
Project on Github: https://github.com/f4b6a3/ulid-creator
How to Use
Create a ULID:
Ulid ulid = UlidCreator.getUlid();
Create a Monotonic ULID:
Ulid ulid = UlidCreator.getMonotonicUlid();
Maven dependency
Add these lines to your pom.xml.
<!-- https://search.maven.org/artifact/com.github.f4b6a3/ulid-creator -->
<dependency>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
<version>4.1.2</version>
</dependency>
See more options in maven.org.
Other usage examples
Create a ULID from a canonical string (26 chars):
Ulid ulid = Ulid.from("0123456789ABCDEFGHJKMNPQRS");
Convert a ULID into a canonical string in upper case:
String string = ulid.toString(); // 0123456789ABCDEFGHJKMNPQRS
Convert a ULID into a canonical string in lower case:
String string = ulid.toLowerCase(); // 0123456789abcdefghjkmnpqrs
Convert a ULID into a UUID:
UUID uuid = ulid.toUuid(); // 0110c853-1d09-52d8-d73e-1194e95b5f19
Convert a ULID into a RFC-4122 UUID v4:
UUID uuid = ulid.toRfc4122().toUuid(); // 0110c853-1d09-42d8-973e-1194e95b5f19
// ^ UUID v4
Convert a ULID into a byte array:
byte[] bytes = ulid.toBytes(); // 16 bytes (128 bits)
Get the creation instant of a ULID:
Instant instant = ulid.getInstant(); // 2007-02-16T02:13:14.633Z
@alizain any chance merging these PRs?
Thank you.