Class Config

  • Direct Known Subclasses:
    ParaConfig

    public abstract class Config
    extends Object
    This class loads configuration settings from a file and sets defaults.
    Author:
    Alex Bogdanovski [alex@erudika.com]
    • Constructor Detail

      • Config

        public Config()
    • Method Detail

      • getConfigFilePath

        public String getConfigFilePath()
        The name of the configuration file, usually 'app-application.conf'.
        Returns:
        prefix-application.conf or the value of @{code config.file} system property.
      • getConfigRootPrefix

        public abstract String getConfigRootPrefix()
        The root prefix of the configuration property names, e.g. "para".
        Returns:
        the root prefix for all config property keys.
      • getConfigValue

        public Object getConfigValue​(String key,
                                     String defaultValue)
        Returns the unwrapped value of a configuration parameter or its default value.
        Parameters:
        key - the param key
        defaultValue - the default value
        Returns:
        object a raw unwrapped value
      • getConfig

        public com.typesafe.config.Config getConfig()
        Returns the Config object.
        Returns:
        the config object
      • getSortedConfigKeys

        public Map<String,​String> getSortedConfigKeys()
        Constructs a sorted set of configuration keys. Heavily relies on the Documented annotation for sort order.
        Returns:
        a set of map of config keys, without the root prefix (path), to config categories.
      • store

        public void store()
        Stores all available configuration to a file, overwriting the existing one. In case of HOCON, the commented lines are collected from existing file and appended at the end.
      • render

        public String render​(boolean asJson,
                             String hoconHeader,
                             String hoconFooter)
        Renders the current configuration as a String, taking into account system properties and ENV precedence ordering.
        Parameters:
        asJson - if true, a JSON object will be rendered, otherwise the HOCON format is used
        hoconHeader - file header
        hoconFooter - file footer
        Returns:
        config as string
      • renderConfigDocumentation

        public String renderConfigDocumentation​(String format,
                                                boolean groupByCategory)
        Renders all configuration options along with their documentation and default values.
        Parameters:
        format - one of "hocon", "json" or "markdown"
        groupByCategory - if true, will group properties by category
        Returns:
        a HOCON, JSON or MD string
      • getConfigMap

        public Map<String,​Object> getConfigMap()
        Returns:
        returns the configuration as a map of keys and values.