Class SnowflakeIdParser
java.lang.Object
cloud.opencode.base.id.snowflake.SnowflakeIdParser
- All Implemented Interfaces:
IdParser<Long, SnowflakeIdParser.ParsedId>
public final class SnowflakeIdParser
extends Object
implements IdParser<Long, SnowflakeIdParser.ParsedId>
Snowflake ID Parser
雪花ID解析器
Parses Snowflake IDs to extract timestamp, datacenter ID, worker ID, and sequence number.
解析雪花ID以提取时间戳、数据中心ID、工作节点ID和序列号。
Features | 主要功能:
- Extract all ID components - 提取所有ID组件
- Configurable bit layout - 可配置位布局
- ID validation - ID验证
Usage Examples | 使用示例:
SnowflakeIdParser parser = SnowflakeIdParser.createDefault();
ParsedId parsed = parser.parse(123456789L);
System.out.println("Time: " + parsed.time());
System.out.println("Datacenter: " + parsed.datacenterId());
System.out.println("Worker: " + parsed.workerId());
System.out.println("Sequence: " + parsed.sequence());
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
Performance | 性能特性:
- Time complexity: O(1) - parse() performs only bitwise shift and mask operations on the 64-bit ID - 时间复杂度: O(1) - parse() 仅对 64 位 ID 执行位移和掩码操作
- Space complexity: O(1) - returns a single ParsedId record with fixed fields - 空间复杂度: O(1) - 返回包含固定字段的单个 ParsedId 记录
- Since:
- JDK 25, opencode-base-id V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordParsed Snowflake ID Result 解析的雪花ID结果 -
Method Summary
Modifier and TypeMethodDescriptionstatic SnowflakeIdParsercreate(SnowflakeConfig config) Creates a parser with configuration 使用配置创建解析器static SnowflakeIdParserCreates a parser with default configuration 使用默认配置创建解析器extractTimestamp(Long id) Extracts the timestamp from an ID 从ID中提取时间戳booleanValidates the ID format 验证ID格式Parses an ID to extract embedded information 解析ID以提取嵌入信息
-
Method Details
-
create
Creates a parser with configuration 使用配置创建解析器- Parameters:
config- the configuration | 配置- Returns:
- parser | 解析器
-
createDefault
Creates a parser with default configuration 使用默认配置创建解析器- Returns:
- parser | 解析器
-
parse
Description copied from interface:IdParserParses an ID to extract embedded information 解析ID以提取嵌入信息- Specified by:
parsein interfaceIdParser<Long, SnowflakeIdParser.ParsedId>- Parameters:
id- the ID to parse | 要解析的ID- Returns:
- parse result | 解析结果
-
extractTimestamp
Description copied from interface:IdParserExtracts the timestamp from an ID 从ID中提取时间戳- Specified by:
extractTimestampin interfaceIdParser<Long, SnowflakeIdParser.ParsedId>- Parameters:
id- the ID | ID- Returns:
- timestamp | 时间戳
-
isValid
-