Class ConfigSubset

All Implemented Interfaces:
InvocationHandler

@API(status=INTERNAL, since="1.0") public class ConfigSubset extends AbstractProxyHandler
Invocation handler for configuration subsets. Invokes configuration methods adding the specified prefix to configuration keys.
Since:
1.0
Version:
1.0, 2025-10
Author:
(w) Iker Hernaez
  • Constructor Details

    • ConfigSubset

      protected ConfigSubset(Config instance, String prefix)
      Creates a new instance.
      Parameters:
      instance - The configuration instance to be proxied.
      prefix - The prefix for configuration keys.
  • Method Details

    • create

      public static Config create(Config config, String prefix)
      Creates a new configuration proxy instance with the specified configuration.
      Parameters:
      config - The proxied configuration instance.
      prefix - The prefix for configuration keys.
      Returns:
      A new configuration proxy instance.
    • create

      public static MutableConfig create(MutableConfig config, String prefix)
      Creates a new configuration proxy instance with the specified configuration.
      Parameters:
      config - The proxied configuration instance.
      prefix - The prefix for configuration keys.
      Returns:
      A new configuration proxy instance.
    • create

      public static WatchableConfig create(WatchableConfig config, String prefix)
      Creates a new configuration proxy instance with the specified configuration.
      Parameters:
      config - The proxied configuration instance.
      prefix - The prefix for configuration keys.
      Returns:
      A new configuration proxy instance.
    • create

      protected static <T extends Config> T create(ClassLoader classLoader, Class<T> type, T config, String prefix)
      Creates a new configuration proxy instance with the specified configuration.
      Type Parameters:
      T - The configuration interface type.
      Parameters:
      classLoader - The class loader to be used for the proxy.
      type - The configuration interface type.
      config - The proxied configuration instance.
      prefix - The prefix for configuration keys.
      Returns:
      A new configuration proxy instance.
    • getInstance

      protected Config getInstance()
      Returns the proxied configuration instance.
      Returns:
      The proxied configuration instance.
    • getPrefix

      protected String getPrefix()
      Returns the prefix for configuration keys.
      Returns:
      The prefix for configuration keys.
    • getEvents

      protected @Nullable EventsHandler getEvents()
      Returns the configuration change events handler.
      Returns:
      The configuration change events handler.
    • asConfigKey

      protected String asConfigKey(String key)
      Converts a property key of this sub-set to a delegated configuration key by adding the prefix.
      Parameters:
      key - The sub-set property key.
      Returns:
      The delegated configuration key.
    • isSubsetKey

      protected boolean isSubsetKey(String key)
      Checks if the specified configuration key belongs to this sub-set by checking the prefix.
      Parameters:
      key - The delegated configuration key.
      Returns:
      true if the key belongs to this sub-set, false otherwise.
    • asSubsetKey

      protected String asSubsetKey(String key)
      Converts a delegated configuration key to a property key of this sub-set by removing the prefix.
      Parameters:
      key - The delegated configuration key.
      Returns:
      The sub-set property key.
    • invoke

      public @Nullable Object invoke(@Nullable Object proxy, Method method, @Nullable Object[] args) throws Throwable
      Throws:
      Throwable
    • handleConfigMethod

      protected @Nullable Object handleConfigMethod(Config proxy, Method method, @Nullable Object[] args) throws ReflectiveOperationException
      Handles Config methods invocations.
      Parameters:
      proxy - The proxy instance.
      method - The invoked method.
      args - The method arguments.
      Returns:
      The method invocation result.
      Throws:
      ReflectiveOperationException - If an error occurs during method invocation.
    • handleMutableMethod

      protected @Nullable Object handleMutableMethod(Method method, @Nullable Object[] args) throws ReflectiveOperationException
      Handles MutableConfig methods invocations.
      Parameters:
      method - The invoked method.
      args - The method arguments.
      Returns:
      The method invocation result.
      Throws:
      ReflectiveOperationException - If an error occurs during method invocation.
    • handleWatchableMethod

      protected @Nullable Object handleWatchableMethod(Method method, @Nullable Object[] args) throws ReflectiveOperationException
      Handles WatchableConfig methods invocations.
      Parameters:
      method - The invoked method.
      args - The method arguments.
      Returns:
      The method invocation result.
      Throws:
      ReflectiveOperationException - If an error occurs during method invocation.
    • getKeys

      protected @Nullable Object getKeys(Method method, @Nullable Object[] args) throws ReflectiveOperationException
      Handles Config.getKeys() and Config.getKeys(String) and Config.getKeys(Predicate) method invocations.
      Parameters:
      method - The invoked method.
      args - The method arguments.
      Returns:
      The method invocation result.
      Throws:
      ReflectiveOperationException - If an error occurs during method invocation.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractProxyHandler
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class AbstractProxyHandler
    • toString

      public String toString()
      Overrides:
      toString in class Object