-
Notifications
You must be signed in to change notification settings - Fork 676
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
Move DOMUtil ConfigNode methods to ConfigNode, with some name changes. #3027
base: main
Are you sure you want to change the base?
Conversation
ConfigNode.requiredStrAttr -> attrRequired ConfigNode.child (ex) -> childRequired ConfigNode.getAll move name to first param; don't use empty set PluginInfo: don't need the XML Node constructor anymore
children = loadSubPlugins(node); | ||
isFromSolrConfig = true; | ||
@VisibleForTesting | ||
PluginInfo(Node node, String err, boolean requireName, boolean requireClass) { |
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.
Don't truly need this but it's a convenience constructor for one test.
It's crazy PluginInfo had duplicated code for Node vs ConfigNode -- no need.
Map<String, String> attrs; | ||
private Map<String, String> attrs; // lazy populated | ||
|
||
public DOMConfigNode(Node node) { |
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.
constructor was misplaced
@@ -94,9 +94,13 @@ public List<ConfigNode> getAll(String name) { | |||
} | |||
|
|||
@Override | |||
public List<ConfigNode> getAll(Predicate<ConfigNode> test, Set<String> matchNames) { | |||
public List<ConfigNode> getAll(Set<String> names, Predicate<ConfigNode> test) { |
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.
name/names should go first in these methods. More logical / good taste.
if (names == null) { | ||
return ConfigNode.super.getAll(names, test); | ||
} |
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.
this actually fixes a bug since this overriding code doesn't handle null names, and an empty names was weird so I made that basically disallowed.
Map<String, String> attributes(); | ||
|
||
/** Mutable copy of {@link #attributes()}, excluding {@code exclusions} keys. */ | ||
default Map<String, String> attributesExcept(String... exclusions) { |
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.
formerly was DOMUtil.toMapExcept. This is a better name and needed documentation. I also added a check for a reasonable number of exclusions, and also pre-initialize the result map size.
default ConfigNode child(String name, Supplier<RuntimeException> err) { | ||
default ConfigNode childRequired(String name, Supplier<RuntimeException> err) { |
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.
I want "required" in the name to better differentiate the overloads
*/ | ||
default List<ConfigNode> getAll(Predicate<ConfigNode> test, String... nodeNames) { |
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.
Didn't need this one
List<ConfigNode> result = new ArrayList<>(); | ||
forEachChild( | ||
it -> { | ||
if (matchNames != null && !matchNames.isEmpty() && !matchNames.contains(it.name())) |
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.
no longer using empty as a reasonable param
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.
I don't think it makes sense for DOMUtil to refer to ConfigNode; the latter is a higher level concept. The methods in here referring to it were itching to be instance methods on ConfigNode, which is much more natural for callers. I don't see why ConfigNode & implementations are doing in SolrJ; there are too many things in SolrJ that don't belong there.
This is mostly what precipitated the substance of this PR.
I didn't rename methods in DOMUtil based on the naming choices in ConfigNode (e.g. toMap -> attributes, ...) but maybe should be for consistency? I'm more inclined to let it be. DOMUtil doesn't have many callers anymore. The code there is ancient.
* Like {@link #attr(String)} but throws an error (incorporating {@code missing_err}) if not | ||
* found. | ||
*/ | ||
default String attrRequired(String name, String missing_err) { |
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.
nit pick, but should this bee missingErr
? Thanks for the docs..
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.
Not an area I understand well, but the diff changes did make things more legible, and i apprecaited the additional comments.
@@ -100,39 +100,23 @@ public String toString() { | |||
} | |||
} | |||
|
|||
/** From XML. */ |
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.
Maybe extend just a bit? From schema.xml? It made me look for a similar constructor that was /** From JSON. */
further down...
ConfigNode.requiredStrAttr -> attrRequired
ConfigNode.child (ex) -> childRequired
ConfigNode.getAll move name to first param; don't use empty set
PluginInfo: don't need the XML Node constructor anymore
A Solr 10-only change