Class ConfigTree

java.lang.Object
net.finmath.util.config.ConfigTree

public class ConfigTree extends Object
Config Tree: A tree based representation of configurations that can be selected with a key-value map describing the selector.

Selector ↦ Configuration

configuration
A configuration is a value (Object) assigned to a selector (Map<String, Object>).
selector
A selector is a key-value map where certain properties (String) have certain values (Object). Properties of the selector are checked in a fixed order, such that a tree is formed, where each property corresponds to a level (depth) in the tree.
default values
Each level has a special branch for DEFAULT VALUES, if the given selector value does not match any value of other nodes.

Selector Key Order

The selector is matched against the configurtion list by checking the keys in a certain order. This oder does not matter if there is a unique value for the given selector, but it may matter if default values have to be assign. See the following example.

Example

The configuration is determied by the value of two properties ("prop1" and "prop2") (the keys). The correspondig configuration value is

prop1prop2value
A142.0
A23141
B11
B22
ADEFAULT_VALUE12
DEFAULT_VALUE213
DEFAULT_VALUEDEFAULT_VALUE66
The list of maps that defines all configurations.

Initialising the class with this configuration we have:
  • If the class is initialized with keyOder = { "prop1" , "prop2" }
    • The selector { "prop1" = "A", "prop2" = 2 } results in the value 3141.
    • The selector { "prop1" = "C", "prop2" = 2 } results in the value 13 (the default branch for prop1 is selected first, under that branch value 2 for "prop2" exists).
    • The selector { "prop1" = "C", "prop2" = 1 } results in the value 66 (the default branch for prop1 is selected first, under that branch no value 1 for "prop2" exists).
  • If the class is initialized with keyOder = { "prop2" , "prop1" }
    • The selector { "prop1" = "A", "prop2" = 2 } results in the value 3141.
    • The selector { "prop1" = "C", "prop2" = 2 } results in the value 13 (the branch "2" for prop2 is selected first, under that branch no value C for "prop1" exists).
    • The selector { "prop1" = "C", "prop2" = 1 } results in an exception that no configuration is found (the branch 1 for prop2 is selected first, under that branch no value C for "prop1" exists).
Author:
Christian Fries
  • Constructor Details

    • ConfigTree

      public ConfigTree(List<String> keyOrder, List<Map<String,​Object>> configs)
      Construct the tree.
      Parameters:
      keyOrder - Order in which the string keys of a selector define the levels of the tree.
      configs - A list, where each element is map of keys to object. The key "value" is interpreted as the configuration value. All other keys are interpreted as configuration properties.
  • Method Details

    • getConfig

      public Object getConfig(Map<String,​Object> selector)
      Get the configuration for a given specification of the properties (selector). The configutation tree is traversed by selecting each route though the value of a specific key in the selector, until the lead node is reached. If keys are missing in the selector of if values do not match a predefined route, a default route is used.
      Parameters:
      selector - Maps the name (String) of a property to its value (Object).
      Returns:
      The configuration value for the given selector.