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

DeepEquals: comparator of SortedSets and SortedMaps is not considered, equality of ordered and unordered collections is inconsistent with JDK #74

Closed
Robyt3 opened this issue Dec 7, 2022 · 2 comments

Comments

@Robyt3
Copy link

Robyt3 commented Dec 7, 2022

The comparison of two SortedSets or SortedMaps with deepEquals does not work as expected, when the SortedSets or SortedMaps are not using the same comparator for ordering the elements. If not the same comparators are used, the method returns wrong results, as the iterators i1 and i2 used in compareOrderedCollection and compareSortedMap return elements in a different order.

With the default implementation of equals, this is not the case:

SortedMap<String, String> map1 = new TreeMap<>(Comparator.naturalOrder());
map1.put("a", "b");
map1.put("c", "d");
SortedMap<String, String> map2 = new TreeMap<>(Comparator.reverseOrder());
map2.put("a", "b");
map2.put("c", "d");
System.out.println(map1.equals(map2)); // true

In the JDK, the equals method of Sets and Maps does not consider the ordering in any case, even for SortedSets and SortedMaps. Instead SortedSets are considered to be equal to Sets (and respectively for Maps) when they contain exactly the same entries:

SortedSet<String> set1 = new TreeSet<>();
Set<String> set2 = new HashSet<>();
System.out.println(set1.equals(set2)); // true

Whereas deepEquals considers those two Sets to be not equal, because they are not both of the type SortedSets.

@jdereg
Copy link
Owner

jdereg commented Oct 7, 2023

This has been corrected and will be released on version 2.1.0.

@jdereg
Copy link
Owner

jdereg commented Oct 31, 2023

Can you verify DeepEquals.deepEquals() works correctly for you? The issue was tied to DeepEquals as far as I recall. I realize you are talking about GraphComparator here. We will take a look at that as it should have same behavior as DeepEquals.

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

No branches or pull requests

2 participants