Class ConfigFinder

Direct Known Subclasses:

public class ConfigFinder extends Object
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • rawConfigs

      protected Map<String,Object> rawConfigs
    • configs

      protected Map<String,Object> configs
  • Constructor Details

    • ConfigFinder

      protected ConfigFinder(String classpathFilePath, String externalFilePath, List<String> environmentVariablesPrefixes, boolean environmentVariablesStripPrefix, List<String> systemPropertiesPrefixes, boolean systemPropertiesStripPrefix, boolean externalFileConfigsOverrideEnvironmentVariables, boolean throwExceptionIfSpecifiedClasspathConfigFileIsNotFound, boolean throwExceptionIfSpecifiedExternalConfigFileIsNotFound)
      This component is not part of the Guice context because you can very easily created circular dependencies with configurations since they are used everywhere.
  • Method Details

    • clearPrefixes

      protected List<String> clearPrefixes(List<String> prefixes)
    • configure

      public static ConfigFinder.ConfigFinderBuilder configure()
    • getClasspathFilePath

      protected String getClasspathFilePath()
    • getExternalFilePath

      protected String getExternalFilePath()
    • getEnvironmentVariablesPrefixes

      protected List<String> getEnvironmentVariablesPrefixes()
    • isEnvironmentVariablesStripPrefix

      protected boolean isEnvironmentVariablesStripPrefix()
    • getSystemPropertiesPrefixes

      protected List<String> getSystemPropertiesPrefixes()
    • isSystemPropertiesStripPrefix

      protected boolean isSystemPropertiesStripPrefix()
    • isExternalFileConfigsOverrideEnvironmentVariables

      protected boolean isExternalFileConfigsOverrideEnvironmentVariables()
    • isThrowExceptionIfSpecifiedClasspathConfigFileIsNotFound

      protected boolean isThrowExceptionIfSpecifiedClasspathConfigFileIsNotFound()
    • isThrowExceptionIfSpecifiedExternalConfigFileIsNotFound

      protected boolean isThrowExceptionIfSpecifiedExternalConfigFileIsNotFound()
    • getConfigs

      protected Map<String,Object> getConfigs()
    • getRawConfigs

      protected Map<String,Object> getRawConfigs()
      Get raw configs, as a Map
    • loadYamlFileConfigs

      protected void loadYamlFileConfigs(File configFile, org.yaml.snakeyaml.Yaml yaml)
    • getEnvironmentVariables

      protected Set<Map.Entry<String,String>> getEnvironmentVariables()
    • getEnvironmentVariablesConfigs

      protected Map<String,Object> getEnvironmentVariablesConfigs()
    • getSystemPropertiesConfigs

      protected Map<String,Object> getSystemPropertiesConfigs()
    • expandMap

      protected Map<String,Object> expandMap(Map<String,Object> sourceMap)
      Parses the keys of the map as "dotted paths" and created an expanded Map from them.
    • mergeMaps

      protected Map<String,Object> mergeMaps(Map<String,Object> map1, Map<String,Object> map2)
      Merges two maps : The elements from the second map override the elements of the first map of the same path, except for Map elements which are merged.
    • getRawConfig

      public Object getRawConfig(String dottedKey)
      Gets a config from the raw Map. The dotted key will be parsed as the path to use.
    • getConfigFromMap

      public Object getConfigFromMap(Map<String,Object> map, String dottedKey)
      Gets a config from the given Map. The dotted key will be parsed as the path to use.
      the config value or null if not found.
    • getConfigFromMap

      public Object getConfigFromMap(Map<String,Object> map, String dottedKey, Object defaultValue)
      Gets a config from the given Map. The dotted key will be parsed as the path to use.
      the config value or the default value if not found.
    • getConfig

      public Object getConfig(String key)
    • getConfig

      public Object getConfig(String key, Object defaultValue)
      Gets an untype config from the config map. If the config isn't there, we'll try to get it from the raw configs map.

      If the resulting config is null, the default value will be returned.

    • getConfigList

      public List<Object> getConfigList(String key)
    • getConfigList

      public List<Object> getConfigList(String key, List<?> defaultValue)
    • getMap

      public Map<String,Object> getMap(String key)
    • getMap

      public Map<String,Object> getMap(String key, Map<String,Object> defaultValue)
    • getMapList

      public List<Map<String,Object>> getMapList(String key)
    • getMapList

      public List<Map<String,Object>> getMapList(String key, List<Map<String,Object>> defaultValue)
    • getString

      public String getString(String key)
    • getString

      public String getString(String key, String defaultValue)
    • getStringList

      public List<String> getStringList(String key)
    • getStringList

      public List<String> getStringList(String key, List<String> defaultValue)
    • getBooleanFromElement

      protected Boolean getBooleanFromElement(Object val)
    • getBoolean

      public Boolean getBoolean(String key)
    • getBoolean

      public Boolean getBoolean(String key, Boolean defaultValue)
    • getBooleanList

      public List<Boolean> getBooleanList(String key)
    • getBooleanList

      public List<Boolean> getBooleanList(String key, List<Boolean> defaultValue)
    • getIntegerFromElement

      protected Integer getIntegerFromElement(Object val)
    • getInteger

      public Integer getInteger(String key)
    • getInteger

      public Integer getInteger(String key, Integer defaultValue)
    • getIntegerList

      public List<Integer> getIntegerList(String key)
    • getIntegerList

      public List<Integer> getIntegerList(String key, List<Integer> defaultValue)
    • getLongFromElement

      protected Long getLongFromElement(Object val)
    • getLong

      public Long getLong(String key)
    • getLong

      public Long getLong(String key, Long defaultValue)
    • getLongList

      public List<Long> getLongList(String key)
    • getLongList

      public List<Long> getLongList(String key, List<Long> defaultValue)
    • getBigDecimalFromElement

      protected BigDecimal getBigDecimalFromElement(Object val)
    • getBigDecimal

      public BigDecimal getBigDecimal(String key)
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
    • getBigDecimalList

      public List<BigDecimal> getBigDecimalList(String key)
    • getBigDecimalList

      public List<BigDecimal> getBigDecimalList(String key, List<BigDecimal> defaultValue)
    • getDateFromElement

      protected Date getDateFromElement(Object date)
    • getDate

      public Date getDate(String key)
    • getDate

      public Date getDate(String key, Date defaultValue)
    • getDateList

      public List<Date> getDateList(String key)
    • getDateList

      public List<Date> getDateList(String key, List<Date> defaultValue)
    • getAppJarDirectory

      protected File getAppJarDirectory()
      If the project is running from an executable .jar file, this will return the directory containing this .jar file.
      the directory path or null if the application is not running from an executable .jar file.
    • getAppRootDirectoryNoJar

      protected File getAppRootDirectoryNoJar()
      If the project is not running from an executable .jar file, this will return the root directory of the project on the file system.
      the directory path or null if the application is running from an executable .jar file.