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

Implement hashCode and equals methods on Member #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/net/fabricmc/tinyremapper/IMappingProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@ public Member(String owner, String name, String desc) {
public String owner;
public String name;
public String desc;

@Override
public int hashCode() {
return (31 * (31 * owner.hashCode()) + name.hashCode()) + desc.hashCode();
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use java.util.Objects.hash for that

}

@Override
public boolean equals(Object other) {
Copy link
Contributor

@Marcono1234 Marcono1234 May 27, 2020

Choose a reason for hiding this comment

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

Maybe it should start with if (other == this) { return true; } for better performance for that case, though I don't know if that is needed

if (!(other instanceof Member)) {
return false;
} else {
Member otherMember = (Member) other;
return owner.equals(otherMember.owner) && name.equals(otherMember.owner) && desc.equals(otherMember.desc);
}
}
}
}