From 2e9100a2d862ebb9dca830e0b1609838a52229d1 Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 10 May 2024 17:41:59 +0900 Subject: [PATCH] [#noissue] Cleanup hashcode --- .../pinpoint/web/applicationmap/link/LinkKey.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkKey.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkKey.java index 97fbfb39511a..19dc964d67ec 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkKey.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkKey.java @@ -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) { @@ -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; }