Enum Class Alphabet

java.lang.Object
java.lang.Enum<Alphabet>
cloud.opencode.base.id.nanoid.Alphabet
All Implemented Interfaces:
Serializable, Comparable<Alphabet>, Constable

public enum Alphabet extends Enum<Alphabet>
Predefined Alphabets for NanoID NanoID预定义字母表

Provides commonly used character sets for NanoID generation.

提供常用的NanoID生成字符集。

Available Alphabets | 可用字母表:

  • DEFAULT - URL-safe (64 chars) | URL安全(64字符)
  • ALPHANUMERIC - Letters and digits | 字母和数字
  • ALPHABETIC - Letters only | 仅字母
  • NUMERIC - Digits only | 仅数字
  • HEX_LOWERCASE/UPPERCASE - Hexadecimal | 十六进制
  • NOLOOK_ALIKE - No ambiguous chars | 无歧义字符

Usage Examples | 使用示例:

NanoIdGenerator gen = NanoIdGenerator.builder()
    .alphabet(Alphabet.ALPHANUMERIC)
    .size(16)
    .build();

String chars = Alphabet.DEFAULT.getChars();
int size = Alphabet.NUMERIC.size();

Features | 主要功能:

  • Predefined character sets for NanoID generation - NanoID生成的预定义字符集
  • URL-safe, numeric, alphanumeric alphabets - URL安全、数字、字母数字字符集
  • Custom alphabet validation - 自定义字符集验证

Security | 安全性:

  • Thread-safe: Yes (immutable enum) - 线程安全: 是(不可变枚举)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Enum Constant Details

    • DEFAULT

      public static final Alphabet DEFAULT
      Default URL-safe alphabet 默认URL安全字母表

      Contains: A-Z, a-z, 0-9, _, -

    • ALPHANUMERIC

      public static final Alphabet ALPHANUMERIC
      Alphanumeric alphabet 字母数字字母表

      Contains: A-Z, a-z, 0-9

    • ALPHABETIC

      public static final Alphabet ALPHABETIC
      Alphabetic only 仅字母

      Contains: A-Z, a-z

    • NUMERIC

      public static final Alphabet NUMERIC
      Numeric only 仅数字

      Contains: 0-9

    • HEX_LOWERCASE

      public static final Alphabet HEX_LOWERCASE
      Hexadecimal lowercase 十六进制小写

      Contains: 0-9, a-f

    • HEX_UPPERCASE

      public static final Alphabet HEX_UPPERCASE
      Hexadecimal uppercase 十六进制大写

      Contains: 0-9, A-F

    • NOLOOK_ALIKE

      public static final Alphabet NOLOOK_ALIKE
      No look-alike characters 无歧义字符

      Excludes: 0, O, 1, l, I to avoid confusion

      排除:0, O, 1, l, I 以避免混淆

  • Method Details

    • values

      public static Alphabet[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Alphabet valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getChars

      public String getChars()
      Gets the character set 获取字符集
      Returns:
      character string | 字符字符串
    • size

      public int size()
      Gets the size of the alphabet 获取字母表大小
      Returns:
      number of characters | 字符数量
    • charAt

      public char charAt(int index)
      Gets a character at index 获取指定索引的字符
      Parameters:
      index - the index | 索引
      Returns:
      character at index | 索引处的字符