Package me.ahoo.cosid

Interface Decorator<D>

Type Parameters:
D - The type of the decorated object
All Known Subinterfaces:
IdGeneratorDecorator
All Known Implementing Classes:
ClockSyncCosIdGenerator, ClockSyncSnowflakeId, DatePrefixIdConverter, DefaultSnowflakeFriendlyId, GroupedPrefixIdConverter, LazyIdGenerator, MockIdGenerator, PrefixIdConverter, StringIdGeneratorDecorator, StringSegmentId, StringSnowflakeId, SuffixIdConverter, UncertaintyIdGenerator

@ThreadSafe public interface Decorator<D>
Decorator pattern interface for wrapping and enhancing ID generators.

This interface implements the Decorator design pattern, allowing implementations to wrap existing ID generators and add additional functionality without modifying the original generator. This is commonly used for adding features like:

  • Custom ID conversion
  • Additional validation
  • Logging or monitoring
  • Caching or buffering

The decorator pattern enables flexible composition of ID generator features, allowing multiple decorators to be chained together to create complex behavior.

Implementations of this interface are expected to be thread-safe and can be used concurrently across multiple threads.

  • Method Summary

    Modifier and Type
    Method
    Description
    Get the actual (wrapped) object that this decorator is enhancing.
    static <D> D
    getActual(D any)
    Recursively get the actual object from a potentially nested decorator chain.
  • Method Details

    • getActual

      @Nonnull D getActual()
      Get the actual (wrapped) object that this decorator is enhancing.

      This method returns the underlying object that this decorator is wrapping. For ID generators, this would typically be the base generator that is being enhanced with additional functionality.

      Returns:
      The actual object being decorated
    • getActual

      static <D> D getActual(D any)
      Recursively get the actual object from a potentially nested decorator chain.

      This utility method traverses a chain of decorators to find the original undecorated object. If the provided object is a decorator, it will recursively call this method on the decorator's actual object until it finds a non-decorator object.

      Type Parameters:
      D - The type of the object
      Parameters:
      any - The object to unwrap (may be a decorator or actual object)
      Returns:
      The unwrapped actual object