Class ConfigParams

All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class ConfigParams extends StringValueMap
Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using getAsXXX() methods.

The keys are case-sensitive, so it is recommended to use consistent C-style as: "my_param"

Configuration parameters can be broken into sections and subsections using dot notation as: "section1.subsection1.param1". Using getSection() method all parameters from specified section can be extracted from a ConfigMap.

The ConfigParams supports serialization from/to plain strings as: "key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z"

ConfigParams are used to pass configurations to IConfigurable objects. They also serve as a basis for more concrete configurations such as ConnectionParams or CredentialParams.

### Example ###

 
 ConfigParams config = ConfigParams.fromTuples(
   "section1.key1", "AAA",
   "section1.key2", 123,
   "section2.key1", true
 );

 config.getAsString("section1.key1"); // Result: AAA
 config.getAsInteger("section1.key1"); // Result: 0

 ConfigParams section1 = config.getSection("section1");
 section1.toString(); // Result: key1=AAA;key2=123
 
 
See Also:
  • Constructor Details

    • ConfigParams

      public ConfigParams()
    • ConfigParams

      public ConfigParams(Map<?,?> values)
      Creates a new ConfigParams and fills it with values.
      Parameters:
      values - (optional) an object to be converted into key-value pairs to initialize this config map.
      See Also:
  • Method Details

    • getSectionNames

      public List<String> getSectionNames()
      Gets a list with all 1st level section names.
      Returns:
      a list of section names stored in this ConfigMap.
    • getSection

      public ConfigParams getSection(String section)
      Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys.
      Parameters:
      section - name of the section to retrieve configuration parameters from.
      Returns:
      all configuration parameters that belong to the section named 'section'.
    • addSection

      public void addSection(String section, ConfigParams sectionParams)
      Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix.
      Parameters:
      section - name of the section where add new parameters
      sectionParams - new parameters to be added.
    • override

      public ConfigParams override(ConfigParams configParams)
      Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object.
      Parameters:
      configParams - ConfigMap with parameters to override the current values.
      Returns:
      a new ConfigParams object.
      See Also:
    • setDefaults

      public ConfigParams setDefaults(ConfigParams defaultConfigParams)
      Set default values from specified ConfigParams and returns a new ConfigParams object.
      Parameters:
      defaultConfigParams - ConfigMap with default parameter values.
      Returns:
      a new ConfigParams object.
      See Also:
    • fromValue

      public static ConfigParams fromValue(Object value)
      Creates a new ConfigParams object filled with key-value pairs from specified object.
      Parameters:
      value - an object with key-value pairs used to initialize a new ConfigParams.
      Returns:
      a new ConfigParams object.
      See Also:
    • fromTuples

      public static ConfigParams fromTuples(Object... tuples)
      Creates a new ConfigParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.
      Parameters:
      tuples - the tuples to fill a new ConfigParams object.
      Returns:
      a new ConfigParams object.
      See Also:
    • fromString

      public static ConfigParams fromString(String line)
      Creates a new ConfigParams object filled with key-value pairs serialized as a string.
      Parameters:
      line - a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
      Returns:
      a new ConfigParams object.
      See Also:
    • mergeConfigs

      public static ConfigParams mergeConfigs(ConfigParams... configs)
      Merges two or more ConfigParams into one. The following ConfigParams override previously defined parameters.
      Parameters:
      configs - a list of ConfigParams objects to be merged.
      Returns:
      a new ConfigParams object.
      See Also: