Add a utility method parseAsTreeMap in NamedPathPruner#630
Open
gbhat618 wants to merge 1 commit intojenkinsci:masterfrom
Open
Add a utility method parseAsTreeMap in NamedPathPruner#630gbhat618 wants to merge 1 commit intojenkinsci:masterfrom
gbhat618 wants to merge 1 commit intojenkinsci:masterfrom
Conversation
jglick
reviewed
Mar 27, 2025
| * @param spec the textual specification | ||
| * @return a hierarchical tree represented as {@code TreeMap<String, Object>}. | ||
| */ | ||
| public static TreeMap<String, Object> parseAsTreeMap(String spec) { |
Member
There was a problem hiding this comment.
Is there a reason this cannot just be typed as a Map?
jglick
reviewed
Mar 27, 2025
| * Each node is represented as a key-value pair in the returned {@code TreeMap}. | ||
| * The value for a key: | ||
| * <ul> | ||
| * <li>Is another {@code TreeMap<String, Object>} for non-leaf nodes.</li> |
Member
There was a problem hiding this comment.
This requires the caller to cast, and even worse to use unchecked conversions. I think it would be better to expose Tree or some interface it implements.
Member
There was a problem hiding this comment.
minimally
interface Something extends Map<String, Something> {}might work
Member
|
Note that the current API does not expose the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently converting a given tree specification into the
NamedPathPruner.Treeparsing logic is present only theNamedPathPrunerclass and not exposed to outside. The parsed valuetreeand it'schildrenare also not exposed outside (imo, it is done from an encapsulation standpoint, which is correct).I have a use cases, I would like to parse the give tree spec, just need the list of keys. Although it would be possible
, [ ], but it will lead to logical mismatch between the parsing logic here and the one implemented for a specific use case.childrenof thetree, it is not good.To expose the parsing logic, merely changing the access specifier of methods related to parsing (
parse,list,nodeetc.) or exposing the parsed value by getter -getTreeorgetChildrenwould break the encapsulation and may lead to problems in the downstream code.This PR proposes to add a utility method without modifying any access specifier or changing state related logic.
I have considered alternatives such as,
NamedPathPrunerUtilto expose the functionalityNamedPathPrunernon-final)but this proposed solution seems better one.
Testing done
Submitter checklist