-
Notifications
You must be signed in to change notification settings - Fork 956
Add getStructured default method, add empty StructuredConfigProperties #6759
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...java/io/opentelemetry/sdk/autoconfigure/spi/internal/EmptyStructuredConfigProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** Empty instance of {@link StructuredConfigProperties}. */ | ||
| final class EmptyStructuredConfigProperties implements StructuredConfigProperties { | ||
|
|
||
| private static final EmptyStructuredConfigProperties INSTANCE = | ||
| new EmptyStructuredConfigProperties(); | ||
|
|
||
| private EmptyStructuredConfigProperties() {} | ||
|
|
||
| static EmptyStructuredConfigProperties getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getString(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Boolean getBoolean(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Integer getInt(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Long getLong(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Double getDouble(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public <T> List<T> getScalarList(String name, Class<T> scalarType) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public StructuredConfigProperties getStructured(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public List<StructuredConfigProperties> getStructuredList(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getPropertyKeys() { | ||
| return Collections.emptySet(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
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.
good point, I hadn't thought about the existing methods already having the default variant