Examples
int port = Config.getInt("app.port", 8090);
String topicName = Config.get("app.topic.name");
List<Integer> codes = Config.getList().ofInt("my.codes", 42, 54);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceExpression evaluation.static interfaceReturn a List of values for a configuration key.static interfaceReturn a Set of values configured. -
Method Summary
Modifier and TypeMethodDescriptionReturn the loaded properties as standard Properties map.eval(Properties properties) Return a copy of the properties with 'eval' run on all the values.Return a required configuration value as String.Return a configuration string value with a given default.booleanReturn a required boolean configuration value.booleanReturn a configuration value as boolean given a default value.getDecimal(String key) Return a decimal configuration value.getDecimal(String key, String defaultValue) Return a decimal configuration value with a default value.getDuration(String key) Return a Duration configuration value.getDuration(String key, String defaultValue) Return a Duration configuration value with a default value.<T extends Enum<T>>
TReturn the enum configuration value.<T extends Enum<T>>
TReturn the enum configuration value with a default value.intReturn a required int configuration value.intReturn a configuration value as int given a default value.default Configuration.ListValuegetList()Deprecated.longReturn a required long configuration value.longReturn a configuration value as long given a default value.getOptional(String key) Return a configuration value that might not exist.default Configuration.SetValuegetSet()Deprecated.Return a URI configuration value.Return a URI configuration value with a default value.Return a URL configuration value.Return a URL configuration value with a default value.list()Return a List of values configured.voidPut the loaded properties into System properties.voidRegister a callback for a change to the given configuration key.voidonChangeBool(String key, Consumer<Boolean> callback) Register a callback for a change to the given configuration key as an Boolean value.voidonChangeInt(String key, Consumer<Integer> callback) Register a callback for a change to the given configuration key as an Int value.voidonChangeLong(String key, Consumer<Long> callback) Register a callback for a change to the given configuration key as an Long value.voidSchedule a task to run periodically with a given delay and period.set()Return a Set of values configured.voidsetProperty(String key, String value) Set a configuration value.intsize()Return the number of configuration properties.
-
Method Details
-
asProperties
Properties asProperties()Return the loaded properties as standard Properties map. -
get
Return a required configuration value as String.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
get
Return a configuration string value with a given default.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getOptional
Return a configuration value that might not exist.- Parameters:
key- The configuration key- Returns:
- The configured value wrapped as optional
-
getBool
Return a required boolean configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getBool
Return a configuration value as boolean given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getInt
Return a required int configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getInt
Return a configuration value as int given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getLong
Return a required long configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getLong
Return a configuration value as long given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getDecimal
Return a decimal configuration value.- Parameters:
key- The configuration key- Returns:
- The configured value
-
getDecimal
Return a decimal configuration value with a default value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getURL
Return a URL configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getURL
Return a URL configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getURI
Return a URI configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getURI
Return a URI configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getDuration
Return a Duration configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getDuration
Return a Duration configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getEnum
Return the enum configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
type- The enum typekey- The configuration key- Returns:
- The configured value
-
getEnum
Return the enum configuration value with a default value.- Parameters:
type- The enum typekey- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
list
Configuration.ListValue list()Return a List of values configured.List<Integer> codes = Config.getList().ofInt("my.codes", 97, 45); -
getList
Deprecated.Deprecated migrate to list(). -
set
Configuration.SetValue set()Return a Set of values configured.Set<String> operations = Config.getSet().of("my.operations", "put","delete"); -
getSet
Deprecated.Deprecated migrate to set(). -
setProperty
Set a configuration value.This will fire an configuration callback listeners that are registered for this key.
-
onChange
Register a callback for a change to the given configuration key.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeInt
Register a callback for a change to the given configuration key as an Int value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeLong
Register a callback for a change to the given configuration key as an Long value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeBool
Register a callback for a change to the given configuration key as an Boolean value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
loadIntoSystemProperties
void loadIntoSystemProperties()Put the loaded properties into System properties. -
size
int size()Return the number of configuration properties. -
schedule
Schedule a task to run periodically with a given delay and period.- Parameters:
delay- delay in milliseconds before task is to be executed.period- time in milliseconds between successive task executions.task- task to be scheduled.
-
eval
Return a copy of the properties with 'eval' run on all the values.
-