Class 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 ConfNG instead.

    Since:
    1.0
    Author:
    Bharat Kumar Malviya
    • 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.
      • get

        public String get​(ConfNGKey key)
        Gets a configuration value for the given key.
      • 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 key
        defaultValue - the fallback default value
        Returns:
        the configuration value, or the provided default if not found
        Since:
        1.1.0
      • getInt

        public Integer getInt​(ConfNGKey key)
        Gets a configuration value as an integer.
      • getBoolean

        public Boolean getBoolean​(ConfNGKey key)
        Gets a configuration value as a boolean.
      • 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 key
        delimiter - 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.
      • getResolvedKeys

        public Set<String> getResolvedKeys()
        Gets all resolved configuration keys.
      • 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 match
        keys - the ConfNGKey implementations to check for prefix matching
        Returns:
        map of matching keys to their source information
        Since:
        1.1.0