Class ConfigSubset

java.lang.Object
dev.orne.config.impl.ConfigSubset
All Implemented Interfaces:
InvocationHandler

@API(status=INTERNAL, since="1.0") public class ConfigSubset extends Object implements InvocationHandler
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(@NotNull @NotNull Config instance, @NotNull @NotNull String prefix)
      Creates a new instance.
      Parameters:
      instance - The configuration instance to be proxied.
      prefix - The prefix for configuration keys.
  • Method Details

    • create

      @NotNull public static @NotNull Config create(@NotNull @NotNull Config config, @NotNull @NotNull 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

      @NotNull public static @NotNull MutableConfig create(@NotNull @NotNull MutableConfig config, @NotNull @NotNull 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

      @NotNull public static @NotNull WatchableConfig create(@NotNull @NotNull WatchableConfig config, @NotNull @NotNull 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

      @NotNull protected static <T extends Config> T create(@NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull Class<T> type, @NotNull T config, @NotNull @NotNull 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

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

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

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

      protected String asConfigKey(@NotNull @NotNull 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(@NotNull @NotNull 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(@NotNull @NotNull 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 Object invoke(Object proxy, @NotNull @NotNull Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • handleObjectMethod

      protected Object handleObjectMethod(@NotNull @NotNull Method method, Object[] args) throws ReflectiveOperationException
      Handles Object 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.
    • proxyEquals

      protected boolean proxyEquals(Object other)
      Checks equality with another proxy instance.
      Parameters:
      other - The other proxy instance.
      Returns:
      true if both proxies are equal, false otherwise.
    • handleConfigMethod

      protected Object handleConfigMethod(@NotNull @NotNull Config proxy, @NotNull @NotNull Method method, 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 Object handleMutableMethod(@NotNull @NotNull Method method, 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 Object handleWatchableMethod(@NotNull @NotNull Method method, 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 Object getKeys(@NotNull @NotNull Method method, 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 Object
    • equals

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

      public String toString()
      Overrides:
      toString in class Object