Skip to content

Commit 22d90b6

Browse files
zeitlingertraskjack-berg
authored
add "get" method to DeclarativeConfigProperties (#7923)
Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Jack Berg <[email protected]>
1 parent 452506e commit 22d90b6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ default DeclarativeConfigProperties getStructured(
201201
return defaultIfNull(getStructured(name), defaultValue);
202202
}
203203

204+
/**
205+
* Returns a {@link DeclarativeConfigProperties} configuration property, or {@link #empty()} if a
206+
* property with {@code name} has not been configured.
207+
*
208+
* <p>This is syntactic sugar for the common operation of calling {@code
209+
* config.getStructured(name, empty())}. If you need to distinguish between a property being set
210+
* but empty vs. not set, use {@link #getStructured(String)}.
211+
*
212+
* @return a map-valued configuration property, or an empty {@link DeclarativeConfigProperties}
213+
* instance if {@code name} has not been configured
214+
* @throws DeclarativeConfigException if the property is not a mapping
215+
*/
216+
default DeclarativeConfigProperties get(String name) {
217+
return getStructured(name, empty());
218+
}
219+
204220
/**
205221
* Returns a list of {@link DeclarativeConfigProperties} configuration property.
206222
*

sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigPropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void treeWalking() {
183183
// Access string at .foo.bar.baz without null checking and without exception.
184184
assertThat(
185185
structuredConfigProps
186-
.getStructured("foo", empty())
186+
.get("foo") // short for getStructured("foo", empty())
187187
.getStructured("bar", empty())
188188
.getString("baz"))
189189
.isNull();

0 commit comments

Comments
 (0)