Class StringIdGeneratorDecorator
- All Implemented Interfaces:
Decorator<IdGenerator>,IdGenerator,IdGeneratorDecorator,Statistical,StringIdGenerator
- Direct Known Subclasses:
MockIdGenerator,StringSegmentId,StringSnowflakeId
This decorator allows customization of how numeric IDs are converted to string format
by wrapping an existing IdGenerator with a custom IdConverter. This is
useful when you want to:
- Use a specific string format (e.g., radix-36 instead of radix-62)
- Add prefixes or suffixes to generated IDs
- Apply custom encoding or transformation to IDs
The decorator follows the standard decorator pattern, delegating ID generation to the wrapped generator while overriding the ID conversion behavior.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final IdGeneratorThe actual ID generator being decorated.protected final IdConverterThe custom ID converter for transforming numeric IDs to string format. -
Constructor Summary
ConstructorsConstructorDescriptionStringIdGeneratorDecorator(IdGenerator actual, IdConverter idConverter) Create a new StringIdGeneratorDecorator with the specified generator and converter. -
Method Summary
Modifier and TypeMethodDescriptionGet the actual (wrapped) ID generator that this decorator is enhancing.Get the custom ID converter used by this decorator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.IdGenerator
generateAsStringMethods inherited from interface me.ahoo.cosid.IdGeneratorDecorator
generate, stat
-
Field Details
-
actual
The actual ID generator being decorated.This is the underlying generator that produces the numeric IDs which will then be converted to string format using the custom converter.
-
idConverter
The custom ID converter for transforming numeric IDs to string format.This converter will be used instead of the default converter provided by the wrapped generator, allowing customization of the string representation.
-
-
Constructor Details
-
StringIdGeneratorDecorator
Create a new StringIdGeneratorDecorator with the specified generator and converter.This constructor creates a decorator that will delegate ID generation to the provided generator but use the specified converter for string conversion.
- Parameters:
actual- The actual ID generator to delegate toidConverter- The custom ID converter for string conversion
-
-
Method Details
-
idConverter
Get the custom ID converter used by this decorator.This method returns the converter that will be used to transform numeric IDs to string format, overriding the default converter of the wrapped generator.
- Specified by:
idConverterin interfaceIdGenerator- Returns:
- The custom ID converter
-
getActual
Get the actual (wrapped) ID generator that this decorator is enhancing.This method returns the underlying ID generator that this decorator is wrapping. All ID generation requests are delegated to this actual generator.
- Specified by:
getActualin interfaceDecorator<IdGenerator>- Specified by:
getActualin interfaceIdGeneratorDecorator- Returns:
- The actual ID generator being decorated
-