private static void normalizePropertyMap(AbstractPropertyMap propertyMap, PropertyDefinitionMap propertyDefinitionMap, boolean normalizeRequiredDefaults, boolean normalizeOptionalDefaults) { Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap(); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) { normalizeProperty(childPropertyDefinition, propertyMap, normalizeRequiredDefaults, normalizeOptionalDefaults); } }
/** * "Normalize" the given configuration according to the given configuration definition. That is, for any optional * properties that are not defined in the top-level configuration Map or any sub-Maps, set them. * Map properties are set with an empty Map, and List properties with an empty List. By default, simple * properties that are missing will be created and set with a null value. However, if normalizeRequiredDefaults is true, * and a simple property is required with a default, this will set the required property to that default value. * If normalizeOptionalDefaults is true, and a simple property is not required but has a default, this will set the * optional property to that default. If a simple property does not have a default defined, no matter what those * "normalize" booleans are, the simple property will still be set to null since this method won't know what value * to set it to anyway. * * @param configuration the configuration to be normalized (must not be null) * @param configurationDefinition the configuration definition to normalize the configuration against (may be null) * @param normalizeRequiredDefaults if true, and a property is required, its default will be set as that property's value * @param normalizeOptionalDefaults if true, and a property is optional, its default will be set as that property's value */ public static void normalizeConfiguration(Configuration configuration, ConfigurationDefinition configurationDefinition, boolean normalizeRequiredDefaults, boolean normalizeOptionalDefaults) { if (configuration == null) { throw new IllegalArgumentException("Configuration parameter is null."); } if (configurationDefinition != null) { Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions(); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) { normalizeProperty(childPropertyDefinition, configuration, normalizeRequiredDefaults, normalizeOptionalDefaults); } } }