Class ScalingAlgorithmRegistryImpl

java.lang.Object
io.artificial.enchantments.internal.scaling.ScalingAlgorithmRegistryImpl
All Implemented Interfaces:
ScalingAlgorithmRegistry

public final class ScalingAlgorithmRegistryImpl extends Object implements ScalingAlgorithmRegistry
Thread-safe implementation of ScalingAlgorithmRegistry.

Uses ConcurrentHashMap for thread-safe concurrent access. Pre-registers all built-in algorithms on construction.

Since:
0.2.0
  • Constructor Details

    • ScalingAlgorithmRegistryImpl

      public ScalingAlgorithmRegistryImpl()
      Creates a new registry and pre-registers all built-in algorithms.
  • Method Details

    • register

      public void register(@NotNull @NotNull String name, @NotNull @NotNull ScalingAlgorithm algorithm)
      Description copied from interface: ScalingAlgorithmRegistry
      Registers a custom scaling algorithm with a unique name.

      The algorithm name must be unique and non-empty. Attempting to register an algorithm with a name that already exists will throw an exception.

      Specified by:
      register in interface ScalingAlgorithmRegistry
      Parameters:
      name - the unique algorithm name (must not be null or empty)
      algorithm - the algorithm implementation (must not be null)
    • get

      @NotNull public @NotNull LevelScaling get(@NotNull @NotNull String name, double... params)
      Description copied from interface: ScalingAlgorithmRegistry
      Gets a scaling algorithm by name with the specified parameters.

      The algorithm creates a LevelScaling instance configured with the provided parameters. The parameters are validated to ensure they produce finite values.

      Specified by:
      get in interface ScalingAlgorithmRegistry
      Parameters:
      name - the algorithm name (must not be null or empty)
      params - the algorithm-specific parameters
      Returns:
      a configured LevelScaling instance
    • hasAlgorithm

      public boolean hasAlgorithm(@NotNull @NotNull String name)
      Description copied from interface: ScalingAlgorithmRegistry
      Checks if an algorithm with the specified name is registered.
      Specified by:
      hasAlgorithm in interface ScalingAlgorithmRegistry
      Parameters:
      name - the algorithm name to check (must not be null)
      Returns:
      true if the algorithm exists
    • getRegisteredNames

      @NotNull public @NotNull Set<String> getRegisteredNames()
      Description copied from interface: ScalingAlgorithmRegistry
      Gets all registered algorithm names.
      Specified by:
      getRegisteredNames in interface ScalingAlgorithmRegistry
      Returns:
      an unmodifiable set of all algorithm names
    • getMetadata

      @NotNull public @NotNull Optional<ScalingAlgorithmMetadata> getMetadata(@NotNull @NotNull String name)
      Description copied from interface: ScalingAlgorithmRegistry
      Gets the metadata for a registered algorithm.
      Specified by:
      getMetadata in interface ScalingAlgorithmRegistry
      Parameters:
      name - the algorithm name (must not be null)
      Returns:
      the algorithm metadata if found, empty otherwise
    • unregister

      public boolean unregister(@NotNull @NotNull String name)
      Description copied from interface: ScalingAlgorithmRegistry
      Unregisters a custom algorithm by name.

      Built-in algorithms cannot be unregistered. Attempting to unregister a built-in algorithm will return false.

      Specified by:
      unregister in interface ScalingAlgorithmRegistry
      Parameters:
      name - the algorithm name to unregister (must not be null)
      Returns:
      true if the algorithm was unregistered, false if not found or built-in