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

io.yawp.commons.config.Config Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.commons.config;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.InputStream;
import java.util.Map;

public class Config {

    private static final String DEFAULT_CONFIG = "yawp.yml";

    private static final String DEFAULT_KEY = "default";

    private Map features;

    public static Config load() {
        return loadYamlFrom(stream(DEFAULT_CONFIG));
    }

    private static InputStream stream(String uri) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(uri);
    }

    private static Config loadYamlFrom(InputStream stream) {
        Constructor constructor = new Constructor(Config.class);
        Yaml yaml = new Yaml(constructor);
        return (Config) yaml.load(stream);
    }

    public Map getFeatures() {
        return features;
    }

    public void setFeatures(Map features) {
        this.features = features;
    }

    public FeaturesConfig getDefaultFeatures() {
        return features.get(DEFAULT_KEY);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy