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

io.quarkiverse.helm.deployment.utils.ValuesHolder Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
package io.quarkiverse.helm.deployment.utils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import io.dekorate.ConfigReference;

public class ValuesHolder {
    private final Map prodValues = new HashMap<>();
    private final Map> valuesByProfile = new HashMap<>();

    public Map getProdValues() {
        return Collections.unmodifiableMap(prodValues);
    }

    public Map> getValuesByProfile() {
        return Collections.unmodifiableMap(valuesByProfile);
    }

    public void put(String property, ConfigReference config) {
        put(property, config, config.getValue(), config.getProfile());
    }

    public void put(String property, ConfigReference config, Object value) {
        prodValues.put(property, new HelmValueHolder(value, config));
    }

    public void put(String property, ConfigReference config, Object value, String profile) {
        get(profile).put(property, new HelmValueHolder(value, config));
    }

    public void putIfAbsent(String property, ConfigReference config, Object value, String profile) {
        get(profile).putIfAbsent(property, new HelmValueHolder(value, config));
    }

    public Map get(String profile) {
        Map values = prodValues;
        if (StringUtils.isNotEmpty(profile)) {
            values = valuesByProfile.computeIfAbsent(profile, p -> new HashMap<>());
        }

        return values;
    }

    public static class HelmValueHolder {
        public final Object value;
        public final ConfigReference configReference;

        public HelmValueHolder(Object value, ConfigReference configReference) {
            this.value = value;
            this.configReference = configReference;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy