32 lines
929 B
Java
32 lines
929 B
Java
package com.baiyue.common.event;
|
|
|
|
import java.util.UUID;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* 事件标识生成与格式判断工具。
|
|
*/
|
|
public final class EventIdentifiers {
|
|
private static final Pattern UUID_PATTERN = Pattern.compile(
|
|
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$");
|
|
private static final Pattern ULID_PATTERN = Pattern.compile(
|
|
"^[0-7][0-9A-HJKMNP-TV-Z]{25}$", Pattern.CASE_INSENSITIVE);
|
|
|
|
private EventIdentifiers() {
|
|
}
|
|
|
|
/**
|
|
* 生成标准 UUID 字符串。
|
|
*/
|
|
public static String newUuid() {
|
|
return UUID.randomUUID().toString();
|
|
}
|
|
|
|
/**
|
|
* 判断字符串是否为标准 UUID 或 26 位 ULID。
|
|
*/
|
|
public static boolean isSupported(String value) {
|
|
return value != null && (UUID_PATTERN.matcher(value).matches() || ULID_PATTERN.matcher(value).matches());
|
|
}
|
|
}
|