Skip to content

fix: implement equals and hashCode in map Coordinate - #10631

Merged
sissbruecker merged 3 commits into
mainfrom
fix/map-coordinate-equals-hashcode
Nov 10, 2026
Merged

sissbruecker merged 3 commits into
mainfrom
fix/map-coordinate-equals-hashcode

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Coordinate is an immutable value class, but it did not override equals or hashCode. Two instances with the same x and y were never equal, so they could not be found in a Set, used as map keys, or checked with contains.

Original contribution by @jay23606 in #10588 — thank you! This PR carries the same change over from that PR.

Fixes #10586

What changed

  • Coordinate.equals(Object) now compares the x and y values using Double.compare.
  • Coordinate.hashCode() is based on the same x and y values, so equal coordinates have equal hash codes.
  • Behavior change: coordinates with the same x and y are now equal, where before only the same instance was.

Test summary

  • Coordinates with the same x and y are equal and have the same hash code.
  • Coordinates differing in x or y are not equal.
  • A coordinate is not equal to null or to an object of another type.

@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Fixed both SonarCloud findings. The null and other-type checks are now in their own test, and those values are passed as Object variables. I didn't just swap the arguments: JUnit calls expected.equals(actual), so swapping would run String.equals or a null check and never reach Coordinate.equals.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Nothing to flag — the changes look good.

@sonarqubecloud

Copy link
Copy Markdown

@sissbruecker
sissbruecker added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 2a72f5e Nov 10, 2026
16 checks passed
@sissbruecker
sissbruecker deleted the fix/map-coordinate-equals-hashcode branch November 10, 2026 11:05
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha6.

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.

Map.Coordinate does not implement proper equals

3 participants