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

com.configcat.LocalMapDataSource Maven / Gradle / Ivy

Go to download

Java SDK for ConfigCat, a feature flag, feature toggle, and configuration management service. That lets you launch new features and change your software configuration remotely without actually (re)deploying code. ConfigCat even helps you do controlled roll-outs like canary releases and blue-green deployments.

The newest version!
package com.configcat;

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

class LocalMapDataSource extends OverrideDataSource {
    private final Map loadedSettings = new HashMap<>();

    public LocalMapDataSource(Map source) {
        if (source == null)
            throw new IllegalArgumentException("'source' cannot be null.");

        for (Map.Entry entry : source.entrySet()) {
            Setting setting = convertToSetting(entry.getValue());
            this.loadedSettings.put(entry.getKey(), setting);
        }
    }

    @Override
    public Map getLocalConfiguration() {
        return this.loadedSettings;
    }

    private Setting convertToSetting(Object object) {
        Setting setting = new Setting();
        SettingValue settingValue = new SettingValue();
        if (object instanceof String) {
            setting.setType(SettingType.STRING);
            settingValue.setStringValue((String) object);
        } else if (object instanceof Boolean) {
            setting.setType(SettingType.BOOLEAN);
            settingValue.setBooleanValue((Boolean) object);
        } else if (object instanceof Integer) {
            setting.setType(SettingType.INT);
            settingValue.setIntegerValue((Integer) object);
        } else if (object instanceof Double) {
            setting.setType(SettingType.DOUBLE);
            settingValue.setDoubleValue((Double) object);
        } else {
            throw new IllegalArgumentException("Only String, Integer, Double or Boolean types are supported.");
        }
        setting.setSettingsValue(settingValue);
        return setting;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy