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

fi.jubic.easyconfig.providers.StaticEnvProvider Maven / Gradle / Ivy

There is a newer version: 0.10.4
Show newest version
package fi.jubic.easyconfig.providers;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * A {@link Map}-backed provider for testing purposes.
 */
public class StaticEnvProvider extends EnvProvider {
    private final Map varMap;

    public StaticEnvProvider() {
        this.varMap = new HashMap<>();
    }

    private void put(String varName, String value) {
        varMap.put(varName, value);
    }

    public StaticEnvProvider with(String varName, String value) {
        put(varName, value);
        return this;
    }

    @Override
    public Optional getVariable(String name) {
        if (!varMap.containsKey(name)) {
            return Optional.empty();
        }
        return Optional.of(varMap.get(name));
    }

    @Override
    protected Stream getNames() {
        return varMap.keySet().stream();
    }

    @Override
    public Map getVariables() {
        return Collections.unmodifiableMap(varMap);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy