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

org.infrastructurebuilder.util.HandCraftedEnvSupplier Maven / Gradle / Ivy

Go to download

Lightly encumberd Standard interfaces (and exceptions) for JVM-based applications within IB codebases

There is a newer version: 0.21.1
Show newest version
/**
 * 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 - 2024 Weber Informatics LLC | Privacy Policy