Package org.actioncontroller.config
Class ConfigMap
- java.lang.Object
-
- java.util.AbstractMap<String,String>
-
- org.actioncontroller.config.ConfigMap
-
public class ConfigMap extends AbstractMap<String,String>
Extracts config values from an inner map or environment variables in a hierarchical fashion. For examplenew ConfigMap(map).subMap("foo").get("bar")will either returnmap.get("foo.bar"),System.getenv("FOO_BAR"), or throwConfigException.The most important operations:
get(Object)returns the prefixed variable specified or environment variable with a comparable name or else throws exceptiongetOrDefault(Object, String)returns the prefixed variable specified or environment variable with a comparable name or default valuesubMap(String)returns aConfigMapwhich resolves all variables relative to the prefixentrySet()gets all entries with a key with the current prefix does not include environment variables
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description ConfigMap(FileListener observer)ConfigMap(FileListener observer, String prefix, Map<String,String> innerMap)ConfigMap(FileListener observer, String prefix, Map<String,String> innerMap, Map<String,String> environment)ConfigMap(FileListener observer, Map<String,String> innerMap)ConfigMap(FileListener observer, Properties properties)
-
Method Summary
-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
ConfigMap
public ConfigMap(FileListener observer, String prefix, Map<String,String> innerMap)
-
ConfigMap
public ConfigMap(FileListener observer, String prefix, Map<String,String> innerMap, Map<String,String> environment)
-
ConfigMap
public ConfigMap(FileListener observer, Map<String,String> innerMap)
-
ConfigMap
public ConfigMap(FileListener observer)
-
ConfigMap
public ConfigMap(FileListener observer, Properties properties)
-
-
Method Detail
-
read
public static ConfigMap read(FileListener observer, File file) throws IOException
- Throws:
IOException
-
optional
public <T> Optional<T> optional(String key, ConfigValueTransformer<String,T> transformer)
-
get
public String get(Object key)
Returns the value of prefix.key or throwsConfigExceptionif missing Use getOrDefault with defaultValue null to support optional values
-
getOrDefault
public String getOrDefault(Object key, String defaultValue)
Returns the value of prefix.key or throwsConfigExceptionif missing
-
getBoolean
public boolean getBoolean(String key)
-
listDirectProperties
public Collection<String> listDirectProperties()
-
getRoot
public ConfigMap getRoot()
-
toString
public String toString()
- Overrides:
toStringin classAbstractMap<String,String>
-
getInetSocketAddress
public InetSocketAddress getInetSocketAddress(String key, int defaultPort)
-
mapOptionalFile
public <T> Optional<T> mapOptionalFile(String key, ConfigValueTransformer<Path,T> transformer) throws Exception
- Throws:
Exception
-
listFiles
public List<Path> listFiles(String key, Path directory, PathMatcher pathMatcher)
-
-