java.lang.Object
net.finmath.util.config.ConfigTree
Config Tree: A tree based representation of configurations that can be selected with a key-value map describing the selector.
Initialising the class with this configuration we have:
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 isprop1 | prop2 | value |
---|---|---|
A | 1 | 42.0 |
A | 2 | 3141 |
B | 1 | 1 |
B | 2 | 2 |
A | DEFAULT_VALUE | 12 |
DEFAULT_VALUE | 2 | 13 |
DEFAULT_VALUE | DEFAULT_VALUE | 66 |
-
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 Summary
Constructors -
Method Summary
-
Constructor Details
-
ConfigTree
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
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.
-