Class Radix62IdConverter
- All Implemented Interfaces:
IdConverter
,Statistical
This converter uses a radix-62 character set consisting of:
- Digits: 0-9 (10 characters)
- Uppercase letters: A-Z (26 characters)
- Lowercase letters: a-z (26 characters)
The resulting string IDs are more compact than decimal representations, using only 11 characters to represent the full range of long values.
Important: If you use the string IDs generated by this converter as database primary keys, you must configure the database to treat the primary key column as case-sensitive, since the character set includes both uppercase and lowercase letters.
Example conversions:
- 12345 → "3d7"
- 9876543210L → "1Zi6jE"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Radix62IdConverter
A shared instance without padding.static final int
The maximum character size for radix-62 encoded IDs.static final Radix62IdConverter
A shared instance with padding.static final int
The radix (base) used for conversion: 62 characters.Fields inherited from class me.ahoo.cosid.converter.RadixIdConverter
PAD_CHAR
-
Constructor Summary
ConstructorsConstructorDescriptionRadix62IdConverter
(boolean padStart, int charSize) Create a new Radix62IdConverter with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic Radix62IdConverter
of
(boolean padStart, int charSize) Get a Radix62IdConverter instance with the specified parameters.Methods inherited from class me.ahoo.cosid.converter.RadixIdConverter
asLong, asString, getCharSize, getMaxId, maxCharSize, offset, stat
-
Field Details
-
MAX_CHAR_SIZE
public static final int MAX_CHAR_SIZEThe maximum character size for radix-62 encoded IDs.This is the maximum number of characters needed to represent any long value in radix-62 format, which is 11 characters.
- See Also:
-
RADIX
public static final int RADIXThe radix (base) used for conversion: 62 characters.This represents the size of the character set used for encoding: 10 digits + 26 uppercase letters + 26 lowercase letters = 62 characters.
- See Also:
-
INSTANCE
A shared instance without padding.This instance converts IDs without padding the result to a fixed length, producing variable-length string IDs.
-
PAD_START
A shared instance with padding.This instance converts IDs with padding to ensure all string IDs have the same length (11 characters), which can be useful for sorting and fixed-width storage requirements.
-
-
Constructor Details
-
Radix62IdConverter
public Radix62IdConverter(boolean padStart, int charSize) Create a new Radix62IdConverter with the specified configuration.This constructor creates a converter with custom padding and character size settings. For most use cases, consider using the
of(boolean, int)
factory method which may return shared instances for better efficiency.- Parameters:
padStart
- Whether to pad the result with leading zeroscharSize
- The character size for padding (if enabled)
-
-
Method Details
-
of
Get a Radix62IdConverter instance with the specified parameters.This factory method returns an appropriate converter instance based on the requested parameters. For common configurations, it returns shared cached instances to improve performance and reduce memory usage.
- Parameters:
padStart
- Whether to pad the result with leading zeroscharSize
- The character size for padding (if enabled)- Returns:
- A Radix62IdConverter instance with the specified configuration
-