Skip to content

Determine Better Equality Rules for ConfigurationNode #69

@Sparky983

Description

@Sparky983

Motivation

#63 is adds diffs like this:

-    when(deserializer.deserialize(eq(node), any())).thenReturn(renderer);
+    final ArgumentMatcher<ConfigurationNode> isValue =
+        arg -> {
+          try {
+            return arg.asString().equals("value");
+          } catch (final DeserializationException e) {
+            return false;
+          }
+        };
+    when(deserializer.deserialize(argThat(isValue), any())).thenReturn(renderer);

which is not ideal as ConfigurationNode.string("value") should be equivalent to a scalar with the value "value".

(IIRC) a lot of the tests depend on this optimisation:

        switch (nodes.size()) {
          /* ... */
          case 1 -> nodes.get(0);
          default -> new CompositeNode(nodes);
        };

that will avoid the creation of a CompositeNode if there is only a single node. This behaviour shouldn't be observable through regular uses of the API such as in tests.

Description

I'm thinking that, in order to hold up the Object::equals contract, if any representations are equal, two nodes themselves are should be considered equal.

This would mean that all the following pairs are all equal:

CompositeNode(ConfigurationNode.string("abc"))
ConfigurationNode.string("abc")

CompositeNode(ConfigurationNode.integer(10), ConfigurationNode.string("abc"))
ConfigurationNode.integer(10)

CompositeNode(
    ConfigurationNode.list(
        ConfigurationNode.integer(10)
    ), 
    ConfigurationNode.string("abc")
)
ConfigurationNode.list(ConfigurationNode.integer(10))

ConfigurationNode.list(
    CompositeNode(
        ConfigurationNode.string("abc"),
        ConfigurationNode.integer(10)
    )
)
ConfigurationNode.list(ConfigurationNode.integer(10))

Alternatives

Alternatively, equality could be defined as two nodes with have the same representations and each representation is equal.

This would mean ConfigurationNode.integer(10) != YamlScalarConfigurationNode("10") because the YamlScalarConfigurationNode represents both the string "10" and the integer 10 whereas the ConfigurationNode.integer represents only the integer 10.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureAPI additionsproposalTo propose features that aren't fully fleshed out (and may be dropped)

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions