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

pl.allegro.tech.embeddedelasticsearch.InstanceSettings Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package pl.allegro.tech.embeddedelasticsearch;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

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

class InstanceSettings {

    private final ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory());
    private final Map settings;

    InstanceSettings() {
        this(Collections.emptyMap());
    }

    InstanceSettings(Map settings) {
        this.settings = Collections.unmodifiableMap(settings);
    }

    InstanceSettings withSetting(String key, Object value) {
        Map extendedSettings = new HashMap<>();
        extendedSettings.putAll(settings);
        extendedSettings.put(key, value);
        return new InstanceSettings(extendedSettings);
    }

    String toYaml() {
        try {
            return yamlObjectMapper.writeValueAsString(settings);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy