Skip to content

A library for Universally Unique Identifiers (UUID).

License

Notifications You must be signed in to change notification settings

fern-flower-lab/uuid-creator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UUID Creator

This is a Java library for generating Universally Unique Identifiers.

UUIDs:

  • UUID Version 1: the time-based version with gregorian epoch specified in RFC-4122;
  • UUID Version 2: the DCE Security version with embedded POSIX UIDs specified in DCE 1.1;
  • UUID Version 3: the name-based version that uses MD5 hashing specified in RFC-4122;
  • UUID Version 4: the randomly or pseudo-randomly generated version specified in RFC-4122;
  • UUID Version 5: the name-based version that uses SHA-1 hashing specified in RFC-4122;
  • UUID Version 6: the time-ordered version with gregorian epoch proposed as new UUID format;
  • UUID Version 7: the time-ordered version with Unix epoch proposed as new UUID format.

COMB GUIDs:

  • Prefix COMB GUID: a combination of random bytes with a prefix (millisecond);
  • Suffix COMB GUID: a combination of random bytes with a suffix (millisecond);
  • Short Prefix COMB GUID: a combination of random bytes with a small prefix (minute);
  • Short Suffix COMB GUID: a combination of random bytes with a small suffix (minute).

This project contains a micro benchmark and a good amount of unit tests.

The jar file can be downloaded directly from maven.org.

Read the Wiki pages and the Javadocs.

Dependency

Add these lines to your pom.xml:

<!-- https://search.maven.org/artifact/com.github.f4b6a3/uuid-creator -->
<dependency>
  <groupId>com.github.f4b6a3</groupId>
  <artifactId>uuid-creator</artifactId>
  <version>5.3.2</version>
</dependency>

See more options in maven.org.

Modularity

Module and bundle names are the same as the root package name.

  • JPMS module name: com.github.f4b6a3.uuid
  • OSGi symbolic name: com.github.f4b6a3.uuid

Usage

All UUID types can be created from the facade UuidCreator.

Create a UUIDv1:

UUID uuid = UuidCreator.getTimeBased();

Create a UUIDv2:

UUID uuid = UuidCreator.getDceSecurity(UuidLocalDomain.LOCAL_DOMAIN_PERSON, 1234);

Create a UUIDv3:

UUID uuid = UuidCreator.getNameBasedMd5(UuidNamespace.NAMESPACE_URL, "https://github.com/");

Create a UUIDv4:

UUID uuid = UuidCreator.getRandomBased();

Create a UUIDv5:

UUID uuid = UuidCreator.getNameBasedSha1(UuidNamespace.NAMESPACE_URL, "https://github.com/");

Create a UUIDv6:

UUID uuid = UuidCreator.getTimeOrdered();

Create a UUIDv7:

UUID uuid = UuidCreator.getTimeOrderedEpoch();

Create a Prefix COMB:

UUID uuid = UuidCreator.getPrefixComb();

Create a Suffix COMB:

UUID uuid = UuidCreator.getSuffixComb();

Create a Short Prefix COMB:

UUID uuid = UuidCreator.getShortPrefixComb();

Create a Short Suffix COMB:

UUID uuid = UuidCreator.getShortSuffixComb();

Alternative

The GUID class is an alternative to the JDK's built-in UUID.

GUID guid = GUID.v1();
GUID guid = GUID.v2(GUID.LOCAL_DOMAIN_PERSON, 1234);
GUID guid = GUID.v3(GUID.NAMESPACE_DNS, "www.example.com");
GUID guid = GUID.v4();
GUID guid = GUID.v5(GUID.NAMESPACE_DNS, "www.example.com");
GUID guid = GUID.v6();
GUID guid = GUID.v7();
GUID guid = GUID.v8(GUID.NAMESPACE_DNS, "www.example.com");

Other identifier generators

Check out the other ID generators from the same family:

License

This library is Open Source software released under the MIT license.

About

A library for Universally Unique Identifiers (UUID).

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • Java 100.0%