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 Summary
ConstructorsModifierConstructorDescriptionprotectedConfigSubset(@NotNull Config instance, @NotNull String prefix) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringasConfigKey(@NotNull String key) Converts a property key of this sub-set to a delegated configuration key by adding the prefix.protected StringasSubsetKey(@NotNull String key) Converts a delegated configuration key to a property key of this sub-set by removing the prefix.static @NotNull ConfigCreates a new configuration proxy instance with the specified configuration.static @NotNull MutableConfigcreate(@NotNull MutableConfig config, @NotNull String prefix) Creates a new configuration proxy instance with the specified configuration.static @NotNull WatchableConfigcreate(@NotNull WatchableConfig config, @NotNull String prefix) Creates a new configuration proxy instance with the specified configuration.protected static <T extends Config>
Tcreate(@NotNull ClassLoader classLoader, @NotNull Class<T> type, T config, @NotNull String prefix) Creates a new configuration proxy instance with the specified configuration.booleanprotected EventsHandlerReturns the configuration change events handler.protected @NotNull ConfigReturns the proxied configuration instance.protected ObjectHandlesConfig.getKeys()andConfig.getKeys(String)andConfig.getKeys(Predicate)method invocations.protected @NotNull StringReturns the prefix for configuration keys.protected ObjecthandleConfigMethod(@NotNull Config proxy, @NotNull Method method, Object[] args) HandlesConfigmethods invocations.protected ObjecthandleMutableMethod(@NotNull Method method, Object[] args) HandlesMutableConfigmethods invocations.protected ObjecthandleObjectMethod(@NotNull Method method, Object[] args) HandlesObjectmethods invocations.protected ObjecthandleWatchableMethod(@NotNull Method method, Object[] args) HandlesWatchableConfigmethods invocations.inthashCode()protected booleanisSubsetKey(@NotNull String key) Checks if the specified configuration key belongs to this sub-set by checking the prefix.protected booleanproxyEquals(Object other) Checks equality with another proxy instance.toString()
-
Constructor Details
-
ConfigSubset
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
Returns the proxied configuration instance.- Returns:
- The proxied configuration instance.
-
getPrefix
Returns the prefix for configuration keys.- Returns:
- The prefix for configuration keys.
-
getEvents
Returns the configuration change events handler.- Returns:
- The configuration change events handler.
-
asConfigKey
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
Checks if the specified configuration key belongs to this sub-set by checking the prefix.- Parameters:
key- The delegated configuration key.- Returns:
trueif the key belongs to this sub-set,falseotherwise.
-
asSubsetKey
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
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-
handleObjectMethod
protected Object handleObjectMethod(@NotNull @NotNull Method method, Object[] args) throws ReflectiveOperationException HandlesObjectmethods 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
Checks equality with another proxy instance.- Parameters:
other- The other proxy instance.- Returns:
trueif both proxies are equal,falseotherwise.
-
handleConfigMethod
protected Object handleConfigMethod(@NotNull @NotNull Config proxy, @NotNull @NotNull Method method, Object[] args) throws ReflectiveOperationException HandlesConfigmethods 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 HandlesMutableConfigmethods 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 HandlesWatchableConfigmethods 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 HandlesConfig.getKeys()andConfig.getKeys(String)andConfig.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() -
equals
-
toString
-