From 08dbeeee650d4792b6aaabb109ccd9504d282804 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 30 Nov 2015 15:02:56 +0100 Subject: [PATCH] add equals and hashcode to Period class --- .../server/computation/period/Period.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java b/server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java index dc4fdf1d8de..86e7c5e9716 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/period/Period.java @@ -20,11 +20,12 @@ package org.sonar.server.computation.period; -import com.google.common.base.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import static com.google.common.base.Objects.toStringHelper; +import static java.util.Objects.hash; import static java.util.Objects.requireNonNull; @Immutable @@ -76,9 +77,30 @@ public class Period { return snapshotId; } + @Override + public boolean equals(@Nullable Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Period period = (Period) o; + return index == period.index + && snapshotDate == period.snapshotDate + && snapshotId == period.snapshotId + && mode.equals(period.mode) + && java.util.Objects.equals(modeParameter, period.modeParameter); + } + + @Override + public int hashCode() { + return hash(index, mode, modeParameter, snapshotDate, snapshotId); + } + @Override public String toString() { - return Objects.toStringHelper(this) + return toStringHelper(this) .add("index", index) .add("mode", mode) .add("modeParameter", modeParameter) -- 2.39.5