Interface IdGeneratorProvider

All Known Implementing Classes:
DefaultIdGeneratorProvider

@ThreadSafe public interface IdGeneratorProvider
Container for managing named IdGenerator instances.

This interface provides a registry for ID generators that can be accessed by name throughout an application. It supports both named generators and a special shared generator that can be used as a default.

The provider acts as a centralized repository for ID generators, enabling:

  • Dependency injection of named generators
  • Centralized configuration and management
  • Easy switching between different generator implementations
  • Sharing of a common generator across multiple components

Common use cases include:

  • Managing different ID generators for different entity types
  • Providing a default generator for components that don't specify one
  • Enabling runtime configuration of ID generation strategies

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

  • Field Details

    • SHARE

      static final String SHARE
      The key used for the shared (default) ID generator.

      This constant defines the name used to access the shared ID generator, which serves as a default generator for components that don't require a specific named generator.

      See Also:
  • Method Details

    • getShare

      IdGenerator getShare()
      Get the shared (default) ID generator.

      This method returns the shared ID generator that can be used as a default when no specific named generator is required.

      Returns:
      The shared ID generator
    • setShare

      void setShare(IdGenerator idGenerator)
      Set the shared (default) ID generator.

      This method updates the shared ID generator that will be returned by getShare().

      Parameters:
      idGenerator - The ID generator to set as shared
    • removeShare

      IdGenerator removeShare()
      Remove the shared (default) ID generator.

      This method removes the current shared ID generator and returns it, leaving no shared generator configured.

      Returns:
      The previous shared ID generator, or null if none was set
    • get

      Get an ID generator by its name.

      This method returns an optional containing the ID generator with the specified name, or an empty optional if no generator with that name exists.

      Parameters:
      name - The name of the ID generator to retrieve
      Returns:
      An optional containing the ID generator, or empty if not found
    • getRequired

      default IdGenerator getRequired(String name)
      Get an ID generator by its name, throwing an exception if not found.

      This method returns the ID generator with the specified name, or throws an IllegalArgumentException if no generator with that name exists.

      Parameters:
      name - The name of the ID generator to retrieve
      Returns:
      The ID generator with the specified name
      Throws:
      IllegalArgumentException - if no generator with the specified name exists
    • set

      void set(String name, IdGenerator idGenerator)
      Set an ID generator with the specified name.

      This method registers an ID generator with the specified name, replacing any existing generator with the same name.

      Parameters:
      name - The name to register the generator under
      idGenerator - The ID generator to register
    • remove

      IdGenerator remove(String name)
      Remove an ID generator by its name.

      This method removes the ID generator with the specified name and returns the removed generator, or null if no generator with that name existed.

      Parameters:
      name - The name of the ID generator to remove
      Returns:
      The removed ID generator, or null if not found
    • clear

      void clear()
      Clear all registered ID generators.

      This method removes all registered ID generators, including the shared generator, leaving the provider empty.

    • entries

      Get all registered ID generator entries.

      This method returns a set of map entries representing all registered ID generators, including their names and instances.

      Returns:
      A set of entries for all registered ID generators
    • getAll

      Get all registered ID generators.

      This method returns a collection of all registered ID generator instances, without their associated names.

      Returns:
      A collection of all registered ID generators