Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Jan 12, 2025

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

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Comment on lines +98 to +100
if (names == null) {
return ConfigNode.super.getAll(names, test);
}
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Comment on lines -74 to +88
default ConfigNode child(String name, Supplier<RuntimeException> err) {
default ConfigNode childRequired(String name, Supplier<RuntimeException> err) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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()))
Copy link
Contributor Author

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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..

Copy link
Contributor

@epugh epugh left a 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. */
Copy link
Contributor

@epugh epugh Jan 12, 2025

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants