ai.databand.config.NormalizedProps Maven / Gradle / Ivy
/*
* © Copyright Databand.ai, an IBM Company 2022
*/
package ai.databand.config;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* Normalizes properties. DBND__TRACKING__ENABLED to dbnd.tracking.enabled.
*/
public class NormalizedProps implements PropertiesSource {
private final Map props;
public NormalizedProps(Map propsToNormalize) {
props = new HashMap<>();
for (Map.Entry prop : propsToNormalize.entrySet()) {
String key = prop.getKey();
String normalizedValue = prop.getValue().trim();
if (key.toLowerCase().startsWith("dbnd")) {
String normalizedKey = key.replace("__", ".").toLowerCase();
props.put(normalizedKey, normalizedValue);
} else {
props.put(key, prop.getValue());
}
}
}
@Override
public Map values() {
return Collections.unmodifiableMap(props);
}
@Override
public Optional getValue(String key) {
return Optional.ofNullable(props.get(key));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy