Package me.ahoo.cosid

Class StringIdGeneratorDecorator

java.lang.Object
me.ahoo.cosid.StringIdGeneratorDecorator
All Implemented Interfaces:
Decorator<IdGenerator>, IdGenerator, IdGeneratorDecorator, Statistical, StringIdGenerator
Direct Known Subclasses:
MockIdGenerator, StringSegmentId, StringSnowflakeId

public class StringIdGeneratorDecorator extends Object implements IdGeneratorDecorator
String ID generator decorator for customizing string ID generation.

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 Details

    • actual

      protected final IdGenerator 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

      protected final IdConverter 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

      public StringIdGeneratorDecorator(IdGenerator actual, IdConverter idConverter)
      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 to
      idConverter - The custom ID converter for string conversion
  • Method Details

    • idConverter

      @Nonnull public IdConverter 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:
      idConverter in interface IdGenerator
      Returns:
      The custom ID converter
    • getActual

      @Nonnull public IdGenerator 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:
      getActual in interface Decorator<IdGenerator>
      Specified by:
      getActual in interface IdGeneratorDecorator
      Returns:
      The actual ID generator being decorated