Package me.ahoo.cosid.converter
Class RadixIdConverter
java.lang.Object
me.ahoo.cosid.converter.RadixIdConverter
- All Implemented Interfaces:
IdConverter,Statistical
- Direct Known Subclasses:
Radix36IdConverter,Radix62IdConverter
Abstract base for radix-based ID converters.
Converts between long IDs and string representations using various radixes (base 36, 62, etc.). Supports optional zero-padding for consistent string length.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charPadding character for fixed-width output. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRadixIdConverter(boolean padStart, int charSize) Creates a new RadixIdConverter. -
Method Summary
Modifier and TypeMethodDescriptionlongConvert aStringtype ID back to itslongrepresentation.@NonNull StringasString(long id) Convert alongtype ID to itsStringrepresentation.intGets the fixed character size.longgetMaxId()Gets the maximum ID representable with this char size.static intmaxCharSize(int radix, int bits) Calculates maximum character size for a given radix and bit count.static intoffset(char digitChar) Gets the offset value for a digit character.stat()Get statistical information about this converter.
-
Field Details
-
PAD_CHAR
public static final char PAD_CHARPadding character for fixed-width output.- See Also:
-
-
Constructor Details
-
RadixIdConverter
protected RadixIdConverter(boolean padStart, int charSize) Creates a new RadixIdConverter.- Parameters:
padStart- whether to pad output with leading zeroscharSize- the fixed character size for output
-
-
Method Details
-
offset
public static int offset(char digitChar) Gets the offset value for a digit character.- Parameters:
digitChar- the character to convert- Returns:
- the offset value (0-61) or -1 if invalid
-
maxCharSize
public static int maxCharSize(int radix, int bits) Calculates maximum character size for a given radix and bit count.- Parameters:
radix- the number basebits- number of bits- Returns:
- maximum characters needed
-
getCharSize
public int getCharSize()Gets the fixed character size.- Returns:
- character size
-
getMaxId
public long getMaxId()Gets the maximum ID representable with this char size.- Returns:
- maximum ID
-
asString
Description copied from interface:IdConverterConvert alongtype ID to itsStringrepresentation.This method transforms a numeric ID into a string format according to the specific conversion algorithm implemented by the converter. For example, a radix converter might convert the number 12345 to "3d7".
- Specified by:
asStringin interfaceIdConverter- Parameters:
id- Thelongtype ID to convert- Returns:
- The
Stringrepresentation of the ID
-
asLong
Description copied from interface:IdConverterConvert aStringtype ID back to itslongrepresentation.This method performs the reverse operation of
IdConverter.asString(long), transforming a string ID back into its original numeric form. Implementations should be able to correctly parse strings generated by theirIdConverter.asString(long)method.- Specified by:
asLongin interfaceIdConverter- Parameters:
idString- TheStringtype ID to convert- Returns:
- The
longrepresentation of the ID
-
stat
Description copied from interface:IdConverterGet statistical information about this converter.This method provides basic statistical information about the converter, including its implementation class name.
- Specified by:
statin interfaceIdConverter- Specified by:
statin interfaceStatistical- Returns:
- Statistical information about this converter
-