-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getStructured default method, add empty StructuredConfigProperties #6759
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6759 +/- ##
=========================================
Coverage 90.02% 90.02%
- Complexity 6475 6488 +13
=========================================
Files 718 719 +1
Lines 19573 19587 +14
Branches 1931 1931
=========================================
+ Hits 17621 17634 +13
- Misses 1353 1354 +1
Partials 599 599 ☔ View full report in Codecov by Sentry. |
/** | ||
* Returns a list of {@link StructuredConfigProperties} configuration property. | ||
* | ||
* @return a list of map-valued configuration property, or {@code defaultValue} if {@code name} | ||
* has not been configured | ||
* @throws ConfigurationException if the property is not a sequence of mappings | ||
*/ | ||
default List<StructuredConfigProperties> getStructuredList( | ||
String name, List<StructuredConfigProperties> defaultValue) { | ||
return defaultIfNull(getStructuredList(name), defaultValue); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you give an example of how you see this method being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a demonstration here in the unit test:
// Validate common pattern of walking down tree path which is not defined
// Access string at .foo.bar.baz without null checking and without exception.
assertThat(
structuredConfigProps
.getStructured("foo", empty())
.getStructured("bar", empty())
.getString("baz"))
.isNull();
I give the same example in the javadoc for the new empty()
method, but should probably copy it here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant specifically the list method, it's not clear to me if that variant is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry for misunderstanding.
At that point, it was just for completeness. Every other accessor has a "get or default" variant, and so it feels out of place for this one omission. Its true that it doesn't have utility for tree walking, but that doesn't mean it doesn't have utility at all. For example, this code for interpreting OTLP headers could be simplified to:
config.getStructuredList("headers", List.of()).forEach(header -> {
String name = header.getString("name");
String value = header.getString("value");
if (name != null && value != null) {
addHeader.accept(name, value);
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other accessor has a "get or default" variant
good point, I hadn't thought about the existing methods already having the default variant
Add
StructuredConfigProperties.getStructured(String, StructuredConfigProperties)
method to assist with walking trees without null checking. Originated from this conversation.