001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube 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 * SonarQube 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 */ 020 021package org.sonar.api.technicaldebt.batch.internal; 022 023import org.apache.commons.lang.builder.ToStringBuilder; 024import org.apache.commons.lang.builder.ToStringStyle; 025import org.sonar.api.rule.RuleKey; 026import org.sonar.api.technicaldebt.batch.Requirement; 027import org.sonar.api.utils.WorkUnit; 028 029import java.util.Date; 030 031public class DefaultRequirement implements Requirement { 032 033 public static final String FUNCTION_LINEAR = "linear"; 034 public static final String FUNCTION_LINEAR_WITH_OFFSET = "linear_offset"; 035 public static final String CONSTANT_ISSUE = "constant_issue"; 036 037 private Integer id; 038 private RuleKey ruleKey; 039 private DefaultCharacteristic characteristic; 040 private DefaultCharacteristic rootCharacteristic; 041 042 private String function; 043 private WorkUnit factor; 044 private WorkUnit offset; 045 046 private Date createdAt; 047 private Date updatedAt; 048 049 public DefaultRequirement() { 050 this.factor = WorkUnit.create(0d, WorkUnit.DEFAULT_UNIT); 051 this.offset = WorkUnit.create(0d, WorkUnit.DEFAULT_UNIT); 052 } 053 054 public Integer id() { 055 return id; 056 } 057 058 public DefaultRequirement setId(Integer id) { 059 this.id = id; 060 return this; 061 } 062 063 public RuleKey ruleKey() { 064 return ruleKey; 065 } 066 067 public DefaultRequirement setRuleKey(RuleKey ruleKey) { 068 this.ruleKey = ruleKey; 069 return this; 070 } 071 072 public DefaultCharacteristic characteristic() { 073 return characteristic; 074 } 075 076 public DefaultRequirement setCharacteristic(DefaultCharacteristic characteristic) { 077 this.characteristic = characteristic; 078 this.characteristic.addRequirement(this); 079 return this; 080 } 081 082 public DefaultCharacteristic rootCharacteristic() { 083 return rootCharacteristic; 084 } 085 086 public DefaultRequirement setRootCharacteristic(DefaultCharacteristic rootCharacteristic) { 087 this.rootCharacteristic = rootCharacteristic; 088 return this; 089 } 090 091 public String function() { 092 return function; 093 } 094 095 public DefaultRequirement setFunction(String function) { 096 this.function = function; 097 return this; 098 } 099 100 public WorkUnit factor() { 101 return factor; 102 } 103 104 public DefaultRequirement setFactor(WorkUnit factor) { 105 this.factor = factor; 106 return this; 107 } 108 109 public WorkUnit offset() { 110 return offset; 111 } 112 113 public DefaultRequirement setOffset(WorkUnit offset) { 114 this.offset = offset; 115 return this; 116 } 117 118 public Date createdAt() { 119 return createdAt; 120 } 121 122 public DefaultRequirement setCreatedAt(Date createdAt) { 123 this.createdAt = createdAt; 124 return this; 125 } 126 127 public Date updatedAt() { 128 return updatedAt; 129 } 130 131 public DefaultRequirement setUpdatedAt(Date updatedAt) { 132 this.updatedAt = updatedAt; 133 return this; 134 } 135 136 137 @Override 138 public String toString() { 139 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 140 } 141 142 @Override 143 public boolean equals(Object o) { 144 if (this == o) { 145 return true; 146 } 147 if (o == null || getClass() != o.getClass()) { 148 return false; 149 } 150 151 DefaultRequirement that = (DefaultRequirement) o; 152 153 if (!characteristic.equals(that.characteristic)) { 154 return false; 155 } 156 if (!ruleKey.equals(that.ruleKey)) { 157 return false; 158 } 159 160 return true; 161 } 162 163 @Override 164 public int hashCode() { 165 int result = ruleKey.hashCode(); 166 result = 31 * result + characteristic.hashCode(); 167 return result; 168 } 169}