Class UuidV4Generator

java.lang.Object
cloud.opencode.base.id.uuid.UuidV4Generator
All Implemented Interfaces:
IdGenerator<UUID>

public final class UuidV4Generator extends Object implements IdGenerator<UUID>
UUID v4 Generator UUID v4生成器

Generates random UUIDs based on RFC 4122 version 4. Uses secure random number generator.

基于RFC 4122版本4生成随机UUID。使用安全随机数生成器。

Features | 主要功能:

  • Cryptographically secure - 加密安全
  • High entropy - 高熵值
  • No central coordination required - 无需中心协调

Usage Examples | 使用示例:

UuidV4Generator gen = UuidV4Generator.create();
UUID uuid = gen.generate();

Performance | 性能特性:

  • ~3M ops/sec single thread - 单线程约3M次/秒
  • ~20M ops/sec with 8 threads - 8线程约20M次/秒

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static UuidV4Generator create()
      Creates a UUID v4 generator 创建UUID v4生成器
      Returns:
      generator | 生成器
    • generate

      public UUID generate()
      Description copied from interface: IdGenerator
      Generates the next ID 生成下一个ID
      Specified by:
      generate in interface IdGenerator<UUID>
      Returns:
      generated ID | 生成的ID
    • generateStr

      public String generateStr()
      Generates a UUID as string 生成UUID字符串
      Returns:
      UUID string | UUID字符串
    • generateSimple

      public String generateSimple()
      Generates a simple UUID (no hyphens) 生成简化UUID(无连字符)
      Returns:
      simple UUID string | 简化UUID字符串
    • getType

      public String getType()
      Description copied from interface: IdGenerator
      Gets the generator type name 获取生成器类型名称
      Specified by:
      getType in interface IdGenerator<UUID>
      Returns:
      type name | 类型名称