uuid-creator Documentation

repository·master·Indexed 20 days ago

https://github.com/f4b6a3/uuid-creator

A Java library for generating RFC 9562 compliant Universally Unique Identifiers (UUIDs). It provides a more comprehensive and performant set of tools than the standard JDK implementation, including support for UUIDv1, UUIDv3, and UUIDv5, as well as a high-performance GUID API and UuidValidator for string validation.

Tokens
1.1K
Snippets
5
Records
6
Agent score
22%

What's inside uuid-creator

  1. Install uuid-creator via Maven or Gradle

    master

    To use this library in your Java project, add the following dependency to your build configuration file.

    ### Maven
    ```xml
    <dependency>
      <groupId>com.github.f4b6a3</groupId>
      <artifactId>uuid-creator</artifactId>
      <version>6.1.1</version>
    </dependency>

    Gradle

    implementation 'com.github.f4b6a3:uuid-creator:6.1.0'
  2. Solve common JDK UUID limitations

    master

    This library provides solutions for several limitations found in the standard JDK java.util.UUID implementation:

    ProblemSolution
    Cannot generate UUIDv1 (Gregorian)Use UuidCreator.getTimeBased()
    Cannot generate UUIDv5 (SHA-1)Use UuidCreator.getNameBasedSha1(...)
    UUIDv3 lacks namespace parameterUse UuidCreator.getNameBasedMd5(...)
    No built-in validation methodUse UuidValidator.isValid(String)
    UUID.randomUUID() performance/entropy issuesUse UuidCreator.getRandomBasedFast() (Note: not cryptographically secure)
    UUID.compareTo() non-alphabetical sortingUse UuidComparator
    UUID.fromString() allows non-standard stringsUse UuidCreator.fromString(String)
  3. Generate various UUID subtypes using UuidCreator

    master

    The UuidCreator facade is the primary way to generate all RFC 9562 compliant UUID subtypes. Use the specific method corresponding to the version you need.

    // UUIDv1: Gregorian time-based
    UUID uuid = UuidCreator.getTimeBased();
    
    // UUIDv2: DCE Security version
    UUID uuid = UuidCreator.getDceSecurity(UuidLocalDomain.LOCAL_DOMAIN_PERSON, 1234);
    
    // UUIDv3: Name-based (MD5)
    UUID uuid = UuidCreator.getNameBasedMd5(UuidNamespace.NAMESPACE_URL, "https://github.com/");
    
    // UUIDv4: Randomly generated
    UUID uuid = UuidCreator.getRandomBased();
    
    // UUIDv5: Name-based (SHA-1)
    UUID uuid = UuidCreator.getNameBasedSha1(UuidNamespace.NAMESPACE_URL, "https://github.com/");
    
    // UUIDv6: Reordered Gregorian time-based
    UUID uuid = UuidCreator.getTimeOrdered();
    
    // UUIDv7: Unix Epoch time-based
    UUID uuid = UuidCreator.getTimeOrderedEpoch();
  4. Use the GUID alternative API for high performance

    master

    The GUID API is a standalone, high-performance alternative to UuidCreator. It is designed for a clean interface and minimal class loading. By default, it uses ThreadLocalRandom (non-cryptographic) for speed, but you can pass a SecureRandom instance for cryptographic security.

    // Standard GUID generation
    GUID guid = GUID.v1();
    GUID guid = GUID.v4();
    GUID guid = GUID.v7();
    
    // Name-based generation
    GUID guid = GUID.v3(GUID.NAMESPACE_DNS, "www.example.com");
    
    // Cryptographically secure generation
    GUID secureGuid = GUID.v4(new SecureRandom());
    
    // Convert to standard JDK UUID
    UUID uuid = GUID.v7().toUUID();