Package org.confng.internal
Class ConfigResolver
- java.lang.Object
-
- org.confng.internal.ConfigResolver
-
public final class ConfigResolver extends Object
Internal helper class responsible for resolving configuration values. This class handles the resolution of configuration values from multiple sources according to their precedence order.This is an internal class and should not be used directly by clients. Use
ConfNGinstead.- Since:
- 1.0
- Author:
- Bharat Kumar Malviya
-
-
Constructor Summary
Constructors Constructor Description ConfigResolver(Supplier<List<ConfigSource>> sourcesSupplier, Supplier<List<ConfNGKey>> keyDiscoverer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringget(ConfNGKey key)Gets a configuration value for the given key.StringgetAllForDisplay(ConfNGKey... keys)Gets all configuration values for display purposes.Map<String,ConfigSourceInfo>getAllSourceInfo(List<ConfNGKey> keys)Gets source information for all resolved configuration keys.Map<String,ConfigSourceInfo>getAllSourceInfo(ConfNGKey... keys)Gets source information for all resolved configuration keys.BooleangetBoolean(ConfNGKey key)Gets a configuration value as a boolean.Map<String,String>getByPrefix(String prefix)Gets all configuration values that match a given prefix.Map<String,ConfigSourceInfo>getByPrefixWithInfo(String prefix, List<ConfNGKey> keys)Gets all configuration values that match a given prefix, with source information.StringgetConfigValue(String key)Gets a configuration value for a given key string.StringgetConfigValueCaseInsensitive(String key)Gets a configuration value using case-insensitive key matching.DoublegetDouble(ConfNGKey key)Gets a configuration value as a double.DurationgetDuration(ConfNGKey key)Gets a configuration value as a Duration.StringgetForDisplay(ConfNGKey key)Gets a configuration value with masking for sensitive data.IntegergetInt(ConfNGKey key)Gets a configuration value as an integer.Set<String>getKeysWithPrefix(String prefix)Gets all configuration keys that match a given prefix.List<String>getList(ConfNGKey key)Gets a configuration value as a list of strings.List<String>getList(ConfNGKey key, String delimiter)Gets a configuration value as a list of strings with a custom delimiter.LonggetLong(ConfNGKey key)Gets a configuration value as a long.Optional<String>getOptional(ConfNGKey key)Gets a configuration value as an Optional.StringgetOrDefault(ConfNGKey key, String defaultValue)Gets a configuration value with a fallback default.StringgetRequired(ConfNGKey key)Gets a required configuration value.Set<String>getResolvedKeys()Gets all resolved configuration keys.intgetResolvedValueCount()Gets the number of resolved configuration values.ConfigSourceInfogetSourceInfo(ConfNGKey key)Gets information about which source provided the value for a configuration key.voidinvalidate()Invalidates the current resolution cache.booleanisResolved()Checks if configuration values have been resolved.voidrefresh()Forces re-resolution of all configuration values.voidresolveAll()Resolves all configuration values from all sources.voidresolveAll(Set<String> keys)Resolves configuration values for the specified keys.
-
-
-
Method Detail
-
invalidate
public void invalidate()
Invalidates the current resolution cache.
-
resolveAll
public void resolveAll()
Resolves all configuration values from all sources.
-
resolveAll
public void resolveAll(Set<String> keys)
Resolves configuration values for the specified keys.
-
getOptional
public Optional<String> getOptional(ConfNGKey key)
Gets a configuration value as an Optional. Returns Optional.empty() if the value is not found and has no default.- Parameters:
key- the configuration key- Returns:
- an Optional containing the value if present, empty otherwise
- Since:
- 1.1.0
-
getRequired
public String getRequired(ConfNGKey key)
Gets a required configuration value. Throws ConfigurationException if the value is not found and has no default.- Parameters:
key- the configuration key- Returns:
- the configuration value (never null)
- Throws:
ConfigurationException- if the value is not found and has no default- Since:
- 1.1.0
-
getOrDefault
public String getOrDefault(ConfNGKey key, String defaultValue)
Gets a configuration value with a fallback default. Returns the provided default if the value is not found and the key has no default.- Parameters:
key- the configuration keydefaultValue- the fallback default value- Returns:
- the configuration value, or the provided default if not found
- Since:
- 1.1.0
-
getLong
public Long getLong(ConfNGKey key)
Gets a configuration value as a long.- Parameters:
key- the configuration key- Returns:
- the configuration value as long, or null if not found and no default
- Throws:
IllegalArgumentException- if the value cannot be converted to long
-
getDouble
public Double getDouble(ConfNGKey key)
Gets a configuration value as a double.- Parameters:
key- the configuration key- Returns:
- the configuration value as double, or null if not found and no default
- Throws:
IllegalArgumentException- if the value cannot be converted to double
-
getList
public List<String> getList(ConfNGKey key)
Gets a configuration value as a list of strings. Values are split by comma and trimmed.- Parameters:
key- the configuration key- Returns:
- the configuration value as a list, or null if not found and no default
-
getList
public List<String> getList(ConfNGKey key, String delimiter)
Gets a configuration value as a list of strings with a custom delimiter.- Parameters:
key- the configuration keydelimiter- the delimiter to split values- Returns:
- the configuration value as a list, or null if not found and no default
-
getDuration
public Duration getDuration(ConfNGKey key)
Gets a configuration value as a Duration. Supports formats: "30s" (seconds), "5m" (minutes), "2h" (hours), "1d" (days), "500ms" (milliseconds), or ISO-8601 duration format (e.g., "PT30S").- Parameters:
key- the configuration key- Returns:
- the configuration value as Duration, or null if not found and no default
- Throws:
IllegalArgumentException- if the value cannot be parsed as a duration
-
getForDisplay
public String getForDisplay(ConfNGKey key)
Gets a configuration value with masking for sensitive data.
-
getAllForDisplay
public String getAllForDisplay(ConfNGKey... keys)
Gets all configuration values for display purposes.
-
refresh
public void refresh()
Forces re-resolution of all configuration values.
-
getResolvedValueCount
public int getResolvedValueCount()
Gets the number of resolved configuration values.
-
isResolved
public boolean isResolved()
Checks if configuration values have been resolved.
-
getConfigValue
public String getConfigValue(String key)
Gets a configuration value for a given key string.
-
getConfigValueCaseInsensitive
public String getConfigValueCaseInsensitive(String key)
Gets a configuration value using case-insensitive key matching.
-
getSourceInfo
public ConfigSourceInfo getSourceInfo(ConfNGKey key)
Gets information about which source provided the value for a configuration key.- Parameters:
key- the configuration key- Returns:
- source information including source name, priority, and value
- Since:
- 1.1.0
-
getAllSourceInfo
public Map<String,ConfigSourceInfo> getAllSourceInfo(ConfNGKey... keys)
Gets source information for all resolved configuration keys.- Parameters:
keys- the configuration keys to get info for- Returns:
- map of key name to source information
- Since:
- 1.1.0
-
getAllSourceInfo
public Map<String,ConfigSourceInfo> getAllSourceInfo(List<ConfNGKey> keys)
Gets source information for all resolved configuration keys.- Parameters:
keys- the configuration keys to get info for- Returns:
- map of key name to source information
- Since:
- 1.1.0
-
getByPrefix
public Map<String,String> getByPrefix(String prefix)
Gets all configuration values that match a given prefix.- Parameters:
prefix- the prefix to match (e.g., "database." or "app.")- Returns:
- map of matching keys to their values
- Since:
- 1.1.0
-
getKeysWithPrefix
public Set<String> getKeysWithPrefix(String prefix)
Gets all configuration keys that match a given prefix.- Parameters:
prefix- the prefix to match (e.g., "database." or "app.")- Returns:
- set of matching keys
- Since:
- 1.1.0
-
getByPrefixWithInfo
public Map<String,ConfigSourceInfo> getByPrefixWithInfo(String prefix, List<ConfNGKey> keys)
Gets all configuration values that match a given prefix, with source information.- Parameters:
prefix- the prefix to matchkeys- the ConfNGKey implementations to check for prefix matching- Returns:
- map of matching keys to their source information
- Since:
- 1.1.0
-
-