-
Notifications
You must be signed in to change notification settings - Fork 116
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
[DISCUSS] move Config#getConfigSources back to returning an Array or List<ConfigSource> ? #67
Comments
Yes, I also stumbled upon the return type of I'd return a |
@gunnarmorling a SortedSet is semantically probably the most correct one. But that requires that the ConfigSource would need to implement the Comparator interface. So I think having a defined sort order and an unmodifyable List is probably the best |
Or simply an array. Makes it immutable automatically. |
How is an array immutable?
Using an interface type (Set) leaves more freedom to implementors, whereas
an array is a fixed type. I wouldn't go for arrays at this time and age
unless it's super perf-critical. Let's not make the API look like it's from
2002 ;)
|
Indeed you are right, moving to SortedSet. |
gnn SortedSet has no index access, you need to resort again. And it's mutable. |
This reverts commit bf78fec. Turns out Iterable is still a tad better than arrays as they are unmodifyable Signed-off-by: Mark Struberg <[email protected]>
Signed-off-by: Mark Struberg <[email protected]>
sticking with Iterable after a discussion with Gunnar |
Signed-off-by: Mark Struberg <[email protected]>
Signed-off-by: Mark Struberg <[email protected]>
This is needed as most use cases need the ConfigSources in the effectively sorted order. They also need it sometimes in descending and for other use cases in ascending ordinal order. This cannot be achieved by an Iterable in easy ways. Array has the implicit advantage that it is automatically immutable. Signed-off-by: Mark Struberg <[email protected]>
This reverts commit bf78fec. Turns out Iterable is still a tad better than arrays as they are unmodifyable Signed-off-by: Mark Struberg <[email protected]>
Signed-off-by: Mark Struberg <[email protected]>
…alues Signed-off-by: Mark Struberg <[email protected]>
Config#getConfigSources originally have been a ConfigSource[] [1,2]
This got moved to an Iterable.
But that way we might end up loosing a few use cases.
The ConfigSources are sorted in a descending way. Means the ones with the highest ordinal are in first position (btw we should define this more precisely). Sometimes you need exactly this ordering. E.g. if you want to know the value of a single key then you iterate from the ConfigSource with the highest ordinal and once you find a value you are done.
But think about e.g. an admin UI as @starksm64 mentioned. In that case you want to start at the ConfigSource with the lowest ordinal and drop all the values into a big Map<String, String>. Then you take the next one and again just drop all the values into the map. Effectively overwriting the lower values IF they got also specified in a higher ordinal ConfigSource.
But for doing that you have to iterate in an ASCENDING way! With just an Iterable you cannot easily do that without having to repackage it, right? So what do we win with the Iterable over a good old array?
LieGrue,
strub
[1] https://github.com/struberg/javaConfig/blob/master/api/src/main/java/io/microprofile/config/Config.java#L85
[2] https://github.com/apache/deltaspike/blob/master/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java#L476
The text was updated successfully, but these errors were encountered: