001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch.debt;
021
022import javax.annotation.CheckForNull;
023import javax.annotation.Nullable;
024import org.sonar.api.utils.Duration;
025import javax.annotation.concurrent.Immutable;
026
027/**
028 * @since 4.3
029 * @deprecated since 6.5 debt model will soon be unavailable on batch side
030 */
031@Deprecated
032@Immutable
033public class DebtRemediationFunction {
034
035  public enum Type {
036    LINEAR, LINEAR_OFFSET, CONSTANT_ISSUE
037  }
038
039  private Type type;
040  private Duration coefficient;
041  private Duration offset;
042
043  private DebtRemediationFunction(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
044    this.type = type;
045    this.coefficient = coefficient;
046    this.offset = offset;
047  }
048
049  public static DebtRemediationFunction create(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
050    return new DebtRemediationFunction(type, coefficient, offset);
051  }
052
053  public static DebtRemediationFunction createLinear(Duration coefficient) {
054    return new DebtRemediationFunction(Type.LINEAR, coefficient, null);
055  }
056
057  public static DebtRemediationFunction createLinearWithOffset(Duration coefficient, Duration offset) {
058    return new DebtRemediationFunction(Type.LINEAR_OFFSET, coefficient, offset);
059  }
060
061  public static DebtRemediationFunction createConstantPerIssue(Duration offset) {
062    return new DebtRemediationFunction(Type.CONSTANT_ISSUE, null, offset);
063  }
064
065  public Type type() {
066    return type;
067  }
068
069  @CheckForNull
070  public Duration coefficient() {
071    return coefficient;
072  }
073
074  @CheckForNull
075  public Duration offset() {
076    return offset;
077  }
078
079  @Override
080  public boolean equals(Object o) {
081    if (this == o) {
082      return true;
083    }
084    if (o == null || getClass() != o.getClass()) {
085      return false;
086    }
087
088    DebtRemediationFunction that = (DebtRemediationFunction) o;
089    if (type != that.type) {
090      return false;
091    }
092    if ((coefficient != null) ? !coefficient.equals(that.coefficient) : (that.coefficient != null)) {
093      return false;
094    }
095    return (offset != null) ? offset.equals(that.offset) : (that.offset == null);
096  }
097
098  @Override
099  public int hashCode() {
100    int result = type.hashCode();
101    result = 31 * result + (coefficient != null ? coefficient.hashCode() : 0);
102    result = 31 * result + (offset != null ? offset.hashCode() : 0);
103    return result;
104  }
105
106  @Override
107  public String toString() {
108    StringBuilder sb = new StringBuilder("DebtRemediationFunction{");
109    sb.append("type=").append(type);
110    sb.append(", coefficient=").append(coefficient);
111    sb.append(", offset=").append(offset);
112    sb.append('}');
113    return sb.toString();
114  }
115}