Skip to content

A Java implementation of TypeID (Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs).

License

Notifications You must be signed in to change notification settings

softprops/typeid-java

Repository files navigation

typeid

Build License Info

A Java implementation of TypeID.

TypeIDs are a modern, type-safe, globally unique identifier based on the upcoming UUIDv7 standard. They provide a ton of nice properties that make them a great choice as the primary identifiers for your data in a database, APIs, and distributed systems. Read more about TypeIDs in their spec.

Installation

To add this library as a dependency in your app add the following to your build

Gradle

implementation("me.lessis:typeid:0.0.2")

Maven

<dependency>
    <groupId>me.lessis</groupId>
    <artifactId>typeid</artifactId>
    <version>0.0.2</version>
</dependency>

Usage

import typeid.TypeID

// generate type ids (prefix_7zzzzzzzzqf3b80018tr001cg3)
var id = new TypeID("prefix");

// parse typed ids from their string representation
var parsed = TypeID.fromString(id.toString());

// this is a fallible operation so the value returned
// is an Optional, present when values are valid, empty when not
parsed.ifPresent(
    id -> {
        System.out.println(
            "prefix %s suffix %s".formmated(
                id.prefix(), id.suffix();
            )
        );
    }
);

// get a java.util.UUID representation of a type id (ffffffff-fff7-78d6-8000-28d60000b203)
id.uuid();

About

A Java implementation of TypeID (Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published