Skip to content

Commit

Permalink
[#noissue] Cleanup hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed May 10, 2024
1 parent a987d70 commit 2e9100a
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
public final class LinkKey {
private final Application from;
private final Application to;

private int hash;

// Precalculate hashCode
private final int hashCode;

public LinkKey(Application from, Application to) {
this.from = Objects.requireNonNull(from, "from");
this.to = Objects.requireNonNull(to, "to");
this.hashCode = hashCode0();
}

public static LinkKey of(String fromApplication, ServiceType fromServiceType, String toApplication, ServiceType toServiceType) {
Expand Down Expand Up @@ -64,13 +66,12 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
final int hash = this.hash;
if (hash != 0) {
return hash;
}
return hashCode;
}

private int hashCode0() {
int result = from.hashCode();
result = 31 * result + to.hashCode();
this.hash = result;
return result;
}

Expand Down

0 comments on commit 2e9100a

Please sign in to comment.