uuid #

Ergonomic UUIDs for Java, with first-class RFC 9562 support.

This library provides static utility methods for generating, parsing, inspecting, and comparing UUIDs in accordance with RFC 9562. It is fully compatible with UUID from the JDK.

This library supports:

  • All standard UUID versions (1, 3, 4, 5, 6, 7, 8)
  • Name-based UUIDs using standard namespaces
  • Correct RFC-compliant UUID comparison
  • UUID timestamp extraction

Getting Started #

Add the Dependency #

Add uuid to your pom.xml.

<dependency>
    <groupId>io.github.nutshellengineering</groupId>
    <artifactId>uuid</artifactId>
    <version>1.0.0</version>
    <scope>compile</scope>
</dependency>

Add uuid to your build.gradle file.

dependencies {
    implementation 'io.github.nutshellengineering:uuid:1.0.0'
}

Add uuid to your build.gradle.kts file.

dependencies {
    implementation("io.github.nutshellengineering:uuid:1.0.0")
}

Example Usage #

Create UUIDs #

import static uu.id.UUIDs.*;

var v1 = v1UUID();                              // Time-based UUID
var v3 = v3UUID(NS.DNS, "example.com");         // MD5
var v4 = v4UUID();                              // Random UUID
var v5 = v5UUID(NS.URL, "https://example.com"); // SHA-1
var v6 = v6UUID();                              // Sortable UUID
var v7 = v7UUID();                              // Unix-time UUID
var v8 = v8UUID();                              // Custom UUID

Compare UUIDs Canonically #

import uu.id.UUIDs;  

list.sort(UUIDs.comparator());  // RFC 9562-compliant sort

Convert from bytes or string #

import static uu.id.UUIDs.*; 

var u1 = uuid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
var u2 = uuid(byteArray);

Timestamp from time-based UUIDs #

import uu.id.UUIDs;

Instant timestamp = UUIDs.realTimestamp(UUIDs.v1UUID());