Class NanoIdBuilder
java.lang.Object
cloud.opencode.base.id.nanoid.NanoIdBuilder
NanoID Generator Builder
NanoID生成器构建器
Fluent builder for creating customized NanoIdGenerator instances.
用于创建自定义NanoIdGenerator实例的流式构建器。
Features | 主要功能:
- Custom size configuration - 自定义长度配置
- Custom alphabet selection - 自定义字母表选择
- Random source configuration - 随机源配置
Usage Examples | 使用示例:
NanoIdGenerator gen = new NanoIdBuilder()
.size(16)
.alphabet(Alphabet.ALPHANUMERIC)
.secureRandom()
.build();
NanoIdGenerator customGen = new NanoIdBuilder()
.size(8)
.alphabet("0123456789")
.build();
Security | 安全性:
- Thread-safe: No (use before build) - 线程安全: 否(在build前使用)
Performance | 性能特性:
- Time complexity: O(1) for build() and all setter methods - 时间复杂度: build() 及所有 setter 方法均为 O(1)
- Space complexity: O(1) - stores only size, alphabet reference, and random source - 空间复杂度: O(1) - 仅存储长度、字母表引用和随机源
- Since:
- JDK 25, opencode-base-id V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
NanoIdBuilder
public NanoIdBuilder()Creates a new builder 创建新的构建器
-
-
Method Details
-
size
Sets the ID length 设置ID长度- Parameters:
size- the length | 长度- Returns:
- this builder | 此构建器
-
alphabet
Sets the alphabet 设置字母表- Parameters:
alphabet- the character set | 字符集- Returns:
- this builder | 此构建器
-
alphabet
Sets the alphabet using predefined enum 使用预定义枚举设置字母表- Parameters:
alphabet- the predefined alphabet | 预定义字母表- Returns:
- this builder | 此构建器
-
random
Sets the random source 设置随机源- Parameters:
random- the random generator | 随机生成器- Returns:
- this builder | 此构建器
-
secureRandom
Uses SecureRandom as random source 使用SecureRandom作为随机源- Returns:
- this builder | 此构建器
-
build
Builds the NanoIdGenerator 构建NanoIdGenerator- Returns:
- the generator | 生成器
-