3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.task.projectanalysis.period;
22 import java.util.Objects;
23 import javax.annotation.CheckForNull;
24 import javax.annotation.Nullable;
25 import javax.annotation.concurrent.Immutable;
27 import static com.google.common.base.MoreObjects.toStringHelper;
28 import static java.util.Objects.hash;
29 import static java.util.Objects.requireNonNull;
33 private final int index;
34 private final String mode;
36 private final String modeParameter;
37 private final long snapshotDate;
38 private final String analysisUuid;
41 * @deprecated replaced by {@link #Period(String, String, long, String)}
44 public Period(int index, String mode, @Nullable String modeParameter, long snapshotDate, String analysisUuid) {
45 if (!isValidPeriodIndex(index)) {
46 throw new IllegalArgumentException(String.format("Period index (%s) must be > 0 and < 6", index));
49 this.mode = requireNonNull(mode);
50 this.modeParameter = modeParameter;
51 this.snapshotDate = snapshotDate;
52 this.analysisUuid = analysisUuid;
55 public Period(String mode, @Nullable String modeParameter, long snapshotDate, String analysisUuid) {
57 this.mode = requireNonNull(mode);
58 this.modeParameter = modeParameter;
59 this.snapshotDate = snapshotDate;
60 this.analysisUuid = analysisUuid;
63 public static boolean isValidPeriodIndex(int i) {
64 return i > 0 && i < 6;
68 * Index of periods is 1-based. It goes from 1 to 5.
69 * @deprecated only leak period can now be defined
72 public int getIndex() {
76 public String getMode() {
81 public String getModeParameter() {
85 public long getSnapshotDate() {
89 public String getAnalysisUuid() {
94 public boolean equals(@Nullable Object o) {
98 if (o == null || getClass() != o.getClass()) {
101 Period period = (Period) o;
102 return index == period.index
103 && snapshotDate == period.snapshotDate
104 && Objects.equals(analysisUuid, period.analysisUuid)
105 && mode.equals(period.mode)
106 && Objects.equals(modeParameter, period.modeParameter);
110 public int hashCode() {
111 return hash(index, mode, modeParameter, snapshotDate, analysisUuid);
115 public String toString() {
116 return toStringHelper(this)
119 .add("modeParameter", modeParameter)
120 .add("snapshotDate", snapshotDate)
121 .add("analysisUuid", analysisUuid)