Class ConfigProperties


  • public class ConfigProperties
    extends Object
    Encapsulates a collection of Java System Properties by name and value. Includes handy methods for providing and identifying application-provided default values and converting from Strings to other common types.
    • Constructor Detail

      • ConfigProperties

        public ConfigProperties​(Map<String,​String> configuredValues)
        Creates a new container of configured values from which specific config properties can be obtained.
        Parameters:
        configuredValues - The configured values, which may have been hardcoded in a Map, read from a config file, or whatever.
      • ConfigProperties

        public ConfigProperties​(Properties configuredValues)
        Creates a new container of configured values from which specific config properties can be obtained.
        Parameters:
        configuredValues - The configured values, which may have been read from a properties file, or obtained from System.getProperties(). If the property set contains entries whose key and value are not both Strings, these entries will be ignored.
    • Method Detail

      • get

        public ConfigProperties.ConfigProperty get​(String name,
                                                   String defaultValue)
        Returns the ConfigProperty instance corresponding to the configured value of the given property, or the default if no configured value exists.
        Parameters:
        name - the property name. Must not be null.
        defaultValue - the value to use if no configured value exists. May be null.
        Returns:
      • getConfigurationSummary

        public String getConfigurationSummary​(String heading)
        Returns a multi-line string containing a list of all the properties that were retrieved from this instance, in the order they were retrieved. Does not list unused values from the map given in the constructor, since these may contain a lot of unrelated information (for example, when using System.getProperties()). This is useful for printing a summary of the configuration in a given subsystem. It also helps users learn about available configuration values.
        Parameters:
        heading - a line of text to print before listing the configuration values