public final class ConfigJ
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.String>
| Modifier and Type | Field and Description |
|---|---|
static ConfigJ |
Empty
Provides a singleton empty instance.
|
static ValueFactory |
valueFactory
Provides the converter to convert Strings to Values.
|
| Modifier and Type | Method and Description |
|---|---|
ConfigJ |
add(java.lang.String key,
java.lang.String value)
Gets a new configuration based on this one with another value added or replaced.
|
ConfigJ |
addAll(java.util.Map<java.lang.String,java.lang.String> map)
Adds a number of elements provided by a second map and returns a new instance with the added elements.
|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
ConfigJ |
drop(java.lang.String key)
Gets a new configuration based on this one with a value removed.
|
ConfigJ |
dropAll(java.lang.Iterable<java.lang.String> keys)
Gets a new configuration based on this one with removal of all the keys given in another collection.
|
ConfigJ |
endingWith(java.lang.String suffix)
Filters the subset of entries ending with a given suffix, returning a new ConfigJ instance.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
static ConfigJ |
from(ConfigJ primary,
ConfigJ fallback)
Constructs an instance using an existing Config with a cascaded fallback.
|
static ConfigJ |
from(ConfigSourceJ source)
Constructs an instance from an input source.
|
static ConfigJ |
from(ConfigSourceJ source,
ConfigJ fallback)
Constructs an instance from an input source and with a cascaded fallback.
|
static ConfigJ |
from(ConfigSourceJ source,
java.util.Set<java.lang.String> requiredKeys)
Constructs an instance from an input source and with a specified set of required keys, usually obtained
from a default instance.
|
static ConfigJ |
from(java.io.File file)
Constructs an instance from a file.
|
static ConfigJ |
from(java.io.File file,
ConfigJ fallback)
Constructs an instance from a file and with a cascaded fallback.
|
static ConfigJ |
from(java.io.File file,
java.util.Set<java.lang.String> requiredKeys)
Constructs an instance from a file and with a specified set of required keys, usually obtained
from a default instance.
|
static ConfigJ |
from(java.util.Map<java.lang.String,java.lang.String> sourceData)
Constructs an instance from a map, keeping the same iteration order.
|
static ConfigJ |
from(ParserJ parser)
Constructs an instance from an input parser.
|
static ConfigJ |
from(ParserJ parser,
ConfigJ fallback)
Constructs an instance using the parser supplied and with a cascaded fallback.
|
static ConfigJ |
from(ParserJ parser,
java.util.Set<java.lang.String> requiredKeys)
Constructs an instance using the parser supplied and with a specified set of required keys, usually obtained
from a default instance.
|
static ConfigJ |
fromClasspath(java.lang.String resourcePath)
Constructs an instance from a classpath resource.
|
static ConfigJ |
fromClasspath(java.lang.String resourcePath,
ConfigJ fallback)
Constructs an instance from a classpath resource and with a cascaded fallback.
|
static ConfigJ |
fromClasspath(java.lang.String resourcePath,
java.util.Set<java.lang.String> requiredKeys)
Constructs an instance from a classpath resource and with a specified set of required keys, usually obtained
from a default instance.
|
java.lang.String |
get(java.lang.Object key)
Gets a required value.
|
java.lang.String |
getOrElse(java.lang.Object key,
java.lang.String defaultValue)
Gets a value, using a default if the key is not found in the configuration.
|
java.lang.String |
getOrNull(java.lang.Object key)
Gets a value if present.
|
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
ConfigJ |
overriddenBy(ConfigSourceJ source)
Constructs a new instance based on source information, using `this` as the fallback.
|
ConfigJ |
overriddenBy(java.io.File file)
Constructs a new instance based on source information, using `this` as the fallback.
|
ConfigJ |
overriddenBy(java.util.Map<java.lang.String,java.lang.String> other)
Constructs a new instance based on source information, using `this` as the fallback.
|
ConfigJ |
overriddenBy(ParserJ parser)
Constructs a new instance based on source information, using `this` as the fallback.
|
java.lang.String |
put(java.lang.String key,
java.lang.String value) |
void |
putAll(java.util.Map<? extends java.lang.String,? extends java.lang.String> m) |
java.lang.String |
remove(java.lang.Object key) |
ConfigJ |
section(java.lang.String sectionName)
If 'ini' file sections are used, this filters the subset of entries in a given section, returning a
new ConfigJ instance.
|
int |
size() |
ConfigJ |
startingWith(java.lang.String prefix)
Filters the subset of entries starting with a given prefix, returning a new ConfigJ instance.
|
<T> T |
toBean(java.lang.Class<T> beanClass)
Copies some or all of this config into a new instance of a specified javabean class.
|
<T> T |
toBean(T bean)
Copies some or all of this config into a specified javabean.
|
java.lang.String |
toString() |
Value |
value(java.lang.Object key)
Gets a required value.
|
Value |
valueOrElse(java.lang.Object key,
java.lang.String defaultValue)
Gets a value, using a default if the key is not found in the configuration.
|
java.util.Collection<java.lang.String> |
values() |
ConfigJ |
verifyKeys(java.util.Set<java.lang.String> requiredKeys)
Provides checking that the configuration keys are exactly as expected.
|
ConfigJ |
verifyKeys(java.util.Set<java.lang.String> requiredKeys,
java.lang.String name)
Provides checking that the configuration keys are exactly as expected.
|
public static final ConfigJ Empty
public static ValueFactory valueFactory
public int size()
size in interface java.util.Map<java.lang.String,java.lang.String>public boolean isEmpty()
isEmpty in interface java.util.Map<java.lang.String,java.lang.String>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.String,java.lang.String>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<java.lang.String,java.lang.String>public java.lang.String get(java.lang.Object key)
get in interface java.util.Map<java.lang.String,java.lang.String>key - the keyjava.util.NoSuchElementException - if the key is not found.public java.lang.String getOrNull(java.lang.Object key)
key - the keypublic java.lang.String getOrElse(java.lang.Object key,
java.lang.String defaultValue)
key - the keydefaultValue - the value to be returned if the key is absentpublic Value valueOrElse(java.lang.Object key, java.lang.String defaultValue)
key - the keydefaultValue - the value to be returned if the key is absentpublic Value value(java.lang.Object key)
key - the keyjava.util.NoSuchElementException - if the key is not found.public <T> T toBean(java.lang.Class<T> beanClass)
throws java.lang.ReflectiveOperationException
section(String) and startingWith(String)).T - the type of the beanbeanClass - the required javabean classjava.lang.ReflectiveOperationException - if it was not possible to create or modify the bean by reflection
for some reasonjava.util.NoSuchElementException - if any key is not found, i.e. the bean properties are not a proper
subset of the available config keys.java.lang.IllegalArgumentException - if the type of the data cannot be coerced to match the type of the
setter / constructor parameter.public <T> T toBean(T bean)
throws java.lang.ReflectiveOperationException
section(String) and startingWith(String)).T - the type of the beanbean - the existing javabeanjava.lang.ReflectiveOperationException - if it was not possible to modify the bean by reflection
for some reasonjava.util.NoSuchElementException - if any key is not found, i.e. the bean properties are not a proper
subset of the available config keys.java.lang.IllegalArgumentException - if the type of the data cannot be coerced to match the type of the
setter.public java.lang.String put(java.lang.String key,
java.lang.String value)
put in interface java.util.Map<java.lang.String,java.lang.String>public java.lang.String remove(java.lang.Object key)
remove in interface java.util.Map<java.lang.String,java.lang.String>public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.String> m)
putAll in interface java.util.Map<java.lang.String,java.lang.String>public void clear()
clear in interface java.util.Map<java.lang.String,java.lang.String>public ConfigJ add(java.lang.String key, java.lang.String value)
public ConfigJ addAll(java.util.Map<java.lang.String,java.lang.String> map)
public ConfigJ drop(java.lang.String key)
public ConfigJ dropAll(java.lang.Iterable<java.lang.String> keys)
public java.util.Set<java.lang.String> keySet()
keySet in interface java.util.Map<java.lang.String,java.lang.String>public java.util.Collection<java.lang.String> values()
values in interface java.util.Map<java.lang.String,java.lang.String>public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
entrySet in interface java.util.Map<java.lang.String,java.lang.String>public boolean equals(java.lang.Object o)
equals in interface java.util.Map<java.lang.String,java.lang.String>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Map<java.lang.String,java.lang.String>hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic ConfigJ section(java.lang.String sectionName)
public ConfigJ startingWith(java.lang.String prefix)
public ConfigJ endingWith(java.lang.String suffix)
public ConfigJ verifyKeys(java.util.Set<java.lang.String> requiredKeys) throws ConfigException
requiredKeys - the specification of what's requiredConfigExceptionpublic ConfigJ verifyKeys(java.util.Set<java.lang.String> requiredKeys, java.lang.String name) throws ConfigException
requiredKeys - the specification of what's requiredname - a diagnostic name used in any error message, e.g. the name of the file (default is "Config")ConfigExceptionpublic ConfigJ overriddenBy(java.util.Map<java.lang.String,java.lang.String> other)
other - the source for the new instance. Note that this could be a `Config`.public ConfigJ overriddenBy(ParserJ parser)
parser - the source for the new instancepublic ConfigJ overriddenBy(ConfigSourceJ source) throws ConfigException
source - the source for the new instanceConfigExceptionpublic ConfigJ overriddenBy(java.io.File file) throws ConfigException
file - the source for the new instanceConfigExceptionpublic static ConfigJ from(java.util.Map<java.lang.String,java.lang.String> sourceData) throws ConfigException
ConfigExceptionpublic static ConfigJ from(java.io.File file) throws ConfigException
ConfigExceptionpublic static ConfigJ from(ConfigSourceJ source) throws ConfigException
ConfigExceptionpublic static ConfigJ fromClasspath(java.lang.String resourcePath) throws ConfigException
ConfigExceptionpublic static ConfigJ from(java.io.File file, ConfigJ fallback) throws ConfigException
ConfigExceptionpublic static ConfigJ from(ConfigSourceJ source, ConfigJ fallback) throws ConfigException
ConfigExceptionpublic static ConfigJ fromClasspath(java.lang.String resourcePath, ConfigJ fallback) throws ConfigException
ConfigExceptionpublic static ConfigJ from(ParserJ parser, ConfigJ fallback)
public static ConfigJ from(ConfigJ primary, ConfigJ fallback)
public static ConfigJ from(java.io.File file, java.util.Set<java.lang.String> requiredKeys) throws ConfigException
ConfigExceptionpublic static ConfigJ from(ConfigSourceJ source, java.util.Set<java.lang.String> requiredKeys) throws ConfigException
ConfigExceptionpublic static ConfigJ fromClasspath(java.lang.String resourcePath, java.util.Set<java.lang.String> requiredKeys) throws ConfigException
ConfigExceptionpublic static ConfigJ from(ParserJ parser, java.util.Set<java.lang.String> requiredKeys) throws ConfigException
ConfigException