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

com.github.zhengframework.configuration.source.InMemoryConfigurationSource Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.github.zhengframework.configuration.source;

import static com.github.zhengframework.configuration.source.EnvironmentVariablesConfigurationSource.convertToPropertiesKey;
import static com.github.zhengframework.configuration.source.EnvironmentVariablesConfigurationSource.formatEnvironmentContext;

import com.github.zhengframework.configuration.environment.Environment;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;

public class InMemoryConfigurationSource extends AbstractConfigurationSource {

  private final Map map;

  public InMemoryConfigurationSource(Map map) {
    this.map = Collections.unmodifiableMap(Objects.requireNonNull(map));
  }

  @Override
  public void init() {

  }

  @Override
  protected Map getConfigurationInternal(Environment environment) {
    String environmentContext = formatEnvironmentContext(environment);
    Map copyMap = new HashMap<>();
    for (Entry entry : map.entrySet()) {
      if (entry.getKey().startsWith(environmentContext)) {
        copyMap
            .put(convertToPropertiesKey(entry.getKey(), environmentContext), entry.getValue());
      }
    }
    return Collections.unmodifiableMap(copyMap);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy