From: Sébastien Lesaint Date: Mon, 30 Nov 2015 14:02:56 +0000 (+0100) Subject: add equals and hashcode to Period class X-Git-Tag: 5.3-RC1~122 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08dbeeee650d4792b6aaabb109ccd9504d282804;p=sonarqube.git add equals and hashcode to Period class --- 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)