![JAR search and dependency download from the Maven repository](/logo.png)
org.infrastructurebuilder.util.HandCraftedEnvSupplier Maven / Gradle / Ivy
/**
* Copyright © 2019 admin ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.infrastructurebuilder.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;
public class HandCraftedEnvSupplier implements EnvSupplier {
private Map map;
public HandCraftedEnvSupplier() {
this(new HashMap());
}
public HandCraftedEnvSupplier(Map map) {
this.map = new HashMap<>();
this.map.putAll(Objects.requireNonNull(map));
}
public HandCraftedEnvSupplier(InputStream props) throws IOException {
this();
Properties p = new Properties();
p.load(Objects.requireNonNull(props));
for (String name : p.keySet().stream().map(Object::toString).collect(Collectors.toSet())) {
this.map.put(name, p.getProperty(name));
}
}
public synchronized HandCraftedEnvSupplier set(String key, String val) {
this.map.put(Objects.requireNonNull(key), Objects.requireNonNull(val));
return this;
}
public synchronized HandCraftedEnvSupplier setAll(Map env) {
this.map.putAll(Objects.requireNonNull(env));
return this;
}
@Override
public Map get() {
return new HashMap<>(this.map);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy