Skip to content

Commit 97be663

Browse files
authored
Merge pull request #152 from scalecube/cosmetic-updates
Added more shortcut methods
2 parents 205f5cb + 3264255 commit 97be663

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

config/src/main/java/io/scalecube/config/ConfigRegistry.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ static ConfigRegistry create(ConfigRegistrySettings settings) {
5959
*/
6060
<T> ObjectConfigProperty<T> objectProperty(String name, Function<String, T> mapper);
6161

62+
/**
63+
* Returns dynamic typed object property. Package name of the class comes as prefix.
64+
*
65+
* @param cfgClass a class of config object instance
66+
* @param <T> a type of config object
67+
* @return property instance
68+
*/
69+
<T> ObjectConfigProperty<T> objectProperty(Class<T> cfgClass);
70+
6271
/**
6372
* Returns current value of object property or defaults.
6473
*
@@ -80,6 +89,17 @@ static ConfigRegistry create(ConfigRegistrySettings settings) {
8089
*/
8190
<T> T objectValue(Map<String, String> bindingMap, Class<T> cfgClass, T defaultValue);
8291

92+
/**
93+
* Returns current value of object property or defaults. Package name of the class comes as
94+
* prefix.
95+
*
96+
* @param cfgClass a class of config object instance
97+
* @param defaultValue default config object
98+
* @param <T> a type of returned config object
99+
* @return property value
100+
*/
101+
<T> T objectValue(Class<T> cfgClass, T defaultValue);
102+
83103
/**
84104
* Returns dynamic typed string property. String property is a base type for all properties and
85105
* each type can be casted to string property.

config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public <T> ObjectConfigProperty<T> objectProperty(
137137
return new ObjectConfigPropertyImpl<>(bindingMap, cfgClass, propertyMap, propertyCallbackMap);
138138
}
139139

140+
@Override
141+
public <T> ObjectConfigProperty<T> objectProperty(Class<T> cfgClass) {
142+
return objectProperty(cfgClass.getPackage().getName(), cfgClass);
143+
}
144+
140145
@Override
141146
public <T> T objectValue(String prefix, Class<T> cfgClass, T defaultValue) {
142147
return objectProperty(prefix, cfgClass).value(defaultValue);
@@ -147,6 +152,11 @@ public <T> T objectValue(Map<String, String> bindingMap, Class<T> cfgClass, T de
147152
return objectProperty(bindingMap, cfgClass).value(defaultValue);
148153
}
149154

155+
@Override
156+
public <T> T objectValue(Class<T> cfgClass, T defaultValue) {
157+
return objectValue(cfgClass.getPackage().getName(), cfgClass, defaultValue);
158+
}
159+
150160
@Override
151161
public StringConfigProperty stringProperty(String name) {
152162
return new StringConfigPropertyImpl(name, propertyMap, propertyCallbackMap);

0 commit comments

Comments
 (0)