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

All tags should implement hashCode() #17

Merged
merged 3 commits into from
Dec 11, 2018
Merged

All tags should implement hashCode() #17

merged 3 commits into from
Dec 11, 2018

Conversation

Querz
Copy link
Owner

@Querz Querz commented Dec 9, 2018

As all Tags override equals(), they must also override hashCode() correctly.
See #15

@coveralls
Copy link

coveralls commented Dec 9, 2018

Pull Request Test Coverage Report for Build 141

  • 11 of 11 (100.0%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 97.362%

Totals Coverage Status
Change from base Build 133: 0.02%
Covered Lines: 1218
Relevant Lines: 1251

💛 - Coveralls

@@ -293,6 +289,13 @@ public boolean equals(Object other) {
return true;
}

@Override
public int hashCode() {
int keyHash = Objects.hash(getValue().keySet().toArray());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you create here and in other cases an array first?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Objects.hash() takes a vararg of objects, meaning that passing in just the key set will calculate the hash code of just the key set. Passing it as an array ensures that it calculates the hash codes for each element individually. That means that two different instance of e.g. a CompoundTag containing the exact same keys with equal values will result in the same hash code.

See Unit Test

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, you seem to have changed it already

@Querz Querz merged commit 5a5e797 into master Dec 11, 2018
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

Successfully merging this pull request may close these issues.

3 participants