All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.databand.config.NormalizedProps Maven / Gradle / Ivy

There is a newer version: 1.0.26.1
Show newest version
/*
 * © 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