Skip to content

Handle nested Pattern in Criteria equals #3615

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

Closed
wants to merge 2 commits into from

Conversation

petitcl
Copy link
Contributor

@petitcl petitcl commented Mar 30, 2021

The equals method of Pattern returns false if two Patterns are equal but are different instances. This is already handled in the equals method of Criteria and works well. However, sometimes a Pattern can be nested in a BasicDBList or in a Document or both, like in the case of a $or operator.

This PR fixes that: it enhances the equals method to manually compare BasicDBLists and Documents using the custom isEqual method. I am not aware of any util that allow to compare 2 collections using a custom isEqual function so I had to implement it manually.

Closes #3414

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 30, 2021
Document leftDocument = (Document) left;
Document rightDocument = (Document) right;

return isEqual(leftDocument.values(), rightDocument.values());
Copy link
Member

@mp911de mp911de Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An equality check for Map-like types requires a comparison of keys and values. Right now, a document could yield equality if only the order of values is the same regardless of the key the values are assigned to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I totally missed that one. I fixed it now: the keys and the values are compared in the case of a Document.

@mp911de mp911de force-pushed the master branch 2 times, most recently from 7f55001 to 9d74734 Compare April 8, 2021 15:14
@mp911de mp911de self-assigned this Apr 12, 2021
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 13, 2021
@mp911de mp911de added this to the 3.0.9 (Neumann SR9) milestone Apr 13, 2021
mp911de pushed a commit that referenced this pull request Apr 13, 2021
mp911de added a commit that referenced this pull request Apr 13, 2021
Fix nullability annotations for isEqual(…) parameters. Fix generics. Reformat code.

Add tests.

See #3414
Original pull request: #3615.
mp911de pushed a commit that referenced this pull request Apr 13, 2021
mp911de added a commit that referenced this pull request Apr 13, 2021
Fix nullability annotations for isEqual(…) parameters. Fix generics. Reformat code.

Add tests.

See #3414
Original pull request: #3615.
mp911de pushed a commit that referenced this pull request Apr 13, 2021
mp911de added a commit that referenced this pull request Apr 13, 2021
Fix nullability annotations for isEqual(…) parameters. Fix generics. Reformat code.

Add tests.

See #3414
Original pull request: #3615.
@mp911de
Copy link
Member

mp911de commented Apr 13, 2021

Thank you for your contribution. That's merged, polished, and backported now.

@mp911de mp911de closed this Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Criteria or toEquals fail if contains regex [DATAMONGO-2559]
3 participants