Interface IdGenerator<T>

Type Parameters:
T - the type of ID generated | 生成的ID类型
All Known Implementing Classes:
AtomicIdGenerator, KsuidGenerator, NanoIdGenerator, RandomIdGenerator, SafeJsSnowflakeGenerator, SegmentIdGenerator, SnowflakeGenerator, TimestampIdGenerator, TsidGenerator, TypedIdGenerator, UlidGenerator, UuidGenerator, UuidV4Generator, UuidV7Generator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface IdGenerator<T>
ID Generator Interface ID生成器接口

Unified interface for all ID generators in this library. Implementations must be thread-safe.

本库所有ID生成器的统一接口。实现必须是线程安全的。

Features | 主要功能:

  • Single ID generation - 单个ID生成
  • Batch ID generation - 批量ID生成
  • Generator type identification - 生成器类型标识

Usage Examples | 使用示例:

IdGenerator<Long> snowflake = SnowflakeGenerator.create();
long id = snowflake.generate();
List<Long> ids = snowflake.generateBatch(100);

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates the next ID 生成下一个ID
    default List<T>
    generateBatch(int count)
    Generates a batch of IDs 批量生成ID
    default String
    Gets the generator type name 获取生成器类型名称
  • Method Details

    • generate

      T generate()
      Generates the next ID 生成下一个ID
      Returns:
      generated ID | 生成的ID
    • generateBatch

      default List<T> generateBatch(int count)
      Generates a batch of IDs 批量生成ID
      Parameters:
      count - the number of IDs to generate | 要生成的ID数量
      Returns:
      list of generated IDs | 生成的ID列表
    • getType

      default String getType()
      Gets the generator type name 获取生成器类型名称
      Returns:
      type name | 类型名称