From dee25eff4c225068ade0d88b19d672d8ba0afd1e Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Mon, 21 Aug 2017 21:41:44 +0200 Subject: [PATCH] Update hashCode() and equals() --- .../java/com/djrapitops/plan/data/TPS.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java index c1f11824a..f19de2090 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/TPS.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/TPS.java @@ -5,6 +5,8 @@ */ package main.java.com.djrapitops.plan.data; +import com.google.common.base.Objects; + /** * Class containing single datapoint of TPS / Players online / CPU Usage / Used Memory / Entity Count / Chunks loaded. * @@ -106,33 +108,22 @@ public class TPS { } @Override - public int hashCode() { - int hash = 3; - hash = 97 * hash + (int) (this.date ^ (this.date >>> 32)); - hash = 97 * hash + (int) (Double.doubleToLongBits(this.ticksPerSecond) ^ (Double.doubleToLongBits(this.ticksPerSecond) >>> 32)); - hash = 97 * hash + this.players; - return hash; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TPS tps = (TPS) o; + return date == tps.date && + Double.compare(tps.ticksPerSecond, ticksPerSecond) == 0 && + players == tps.players && + Double.compare(tps.cpuUsage, cpuUsage) == 0 && + usedMemory == tps.usedMemory && + entityCount == tps.entityCount && + chunksLoaded == tps.chunksLoaded; } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null) { - return false; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final TPS other = (TPS) obj; - return date == other.date - && Double.compare(this.ticksPerSecond, other.ticksPerSecond) == 0 - && this.players == other.players - && Double.compare(cpuUsage, other.cpuUsage) == 0; + public int hashCode() { + return Objects.hashCode(date, ticksPerSecond, players, cpuUsage, usedMemory, entityCount, chunksLoaded); } @Override