001 /* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 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 021 package org.sonar.api.technicaldebt.server.internal; 022 023 import org.apache.commons.lang.builder.ToStringBuilder; 024 import org.apache.commons.lang.builder.ToStringStyle; 025 import org.sonar.api.rule.RuleKey; 026 import org.sonar.api.technicaldebt.server.Characteristic; 027 import org.sonar.api.utils.WorkUnit; 028 import org.sonar.api.utils.internal.WorkDuration; 029 030 import javax.annotation.CheckForNull; 031 import javax.annotation.Nullable; 032 033 /** 034 * @since 4.1 035 * @deprecated since 4.3. 036 */ 037 @Deprecated 038 public class DefaultCharacteristic implements Characteristic { 039 040 private Integer id; 041 private String key; 042 private String name; 043 private Integer order; 044 private Integer parentId; 045 private Integer rootId; 046 private RuleKey ruleKey; 047 private String function; 048 private Integer factorValue; 049 private WorkDuration.UNIT factorUnit; 050 private Integer offsetValue; 051 private WorkDuration.UNIT offsetUnit; 052 053 public Integer id() { 054 return id; 055 } 056 057 public DefaultCharacteristic setId(Integer id) { 058 this.id = id; 059 return this; 060 } 061 062 @CheckForNull 063 public String key() { 064 return key; 065 } 066 067 public DefaultCharacteristic setKey(@Nullable String key) { 068 this.key = key; 069 return this; 070 } 071 072 @CheckForNull 073 public String name() { 074 return name; 075 } 076 077 public DefaultCharacteristic setName(@Nullable String name) { 078 this.name = name; 079 return this; 080 } 081 082 @CheckForNull 083 public Integer order() { 084 return order; 085 } 086 087 public DefaultCharacteristic setOrder(@Nullable Integer order) { 088 this.order = order; 089 return this; 090 } 091 092 @CheckForNull 093 public Integer parentId() { 094 return parentId; 095 } 096 097 public DefaultCharacteristic setParentId(@Nullable Integer parentId) { 098 this.parentId = parentId; 099 return this; 100 } 101 102 @CheckForNull 103 public Integer rootId() { 104 return rootId; 105 } 106 107 public DefaultCharacteristic setRootId(@Nullable Integer rootId) { 108 this.rootId = rootId; 109 return this; 110 } 111 112 /** 113 * @deprecated since 4.2 114 */ 115 @Deprecated 116 @CheckForNull 117 public RuleKey ruleKey() { 118 return ruleKey; 119 } 120 121 /** 122 * @deprecated since 4.2 123 */ 124 @Deprecated 125 public DefaultCharacteristic setRuleKey(@Nullable RuleKey ruleKey) { 126 this.ruleKey = ruleKey; 127 return this; 128 } 129 130 /** 131 * @deprecated since 4.2 132 */ 133 @Deprecated 134 @CheckForNull 135 public String function() { 136 return function; 137 } 138 139 /** 140 * @deprecated since 4.2 141 */ 142 @Deprecated 143 public DefaultCharacteristic setFunction(@Nullable String function) { 144 this.function = function; 145 return this; 146 } 147 148 /** 149 * @deprecated since 4.2 150 */ 151 @Deprecated 152 @CheckForNull 153 public WorkUnit factor() { 154 if (factorValue != null && factorUnit != null) { 155 return WorkUnit.create((double) factorValue, fromUnit(factorUnit)); 156 } 157 return null; 158 } 159 160 /** 161 * @deprecated since 4.2 162 */ 163 @Deprecated 164 public DefaultCharacteristic setFactor(@Nullable WorkUnit factor) { 165 if (factor != null) { 166 this.factorValue = (int) factor.getValue(); 167 this.factorUnit = toUnit(factor.getUnit()); 168 } 169 return this; 170 } 171 172 /** 173 * @deprecated since 4.3 174 */ 175 @Deprecated 176 @CheckForNull 177 public Integer factorValue() { 178 return factorValue; 179 } 180 181 /** 182 * @deprecated since 4.3 183 */ 184 @Deprecated 185 public DefaultCharacteristic setFactorValue(@Nullable Integer factorValue) { 186 this.factorValue = factorValue; 187 return this; 188 } 189 190 @CheckForNull 191 public WorkDuration.UNIT factorUnit() { 192 return factorUnit; 193 } 194 195 /** 196 * @deprecated since 4.3 197 */ 198 @Deprecated 199 public DefaultCharacteristic setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) { 200 this.factorUnit = factorUnit; 201 return this; 202 } 203 204 /** 205 * @deprecated since 4.2 206 */ 207 @Deprecated 208 public WorkUnit offset() { 209 if (offsetValue != null && offsetUnit != null) { 210 return WorkUnit.create((double) offsetValue, fromUnit(offsetUnit)); 211 } 212 return null; 213 } 214 215 /** 216 * @deprecated since 4.2 217 */ 218 @Deprecated 219 public DefaultCharacteristic setOffset(@Nullable WorkUnit offset) { 220 if (offset != null) { 221 this.offsetValue = (int) offset.getValue(); 222 this.offsetUnit = toUnit(offset.getUnit()); 223 } 224 return this; 225 } 226 227 /** 228 * @deprecated since 4.3 229 */ 230 @Deprecated 231 @CheckForNull 232 public Integer offsetValue() { 233 return offsetValue; 234 } 235 236 /** 237 * @deprecated since 4.3 238 */ 239 @Deprecated 240 public DefaultCharacteristic setOffsetValue(@Nullable Integer offsetValue) { 241 this.offsetValue = offsetValue; 242 return this; 243 } 244 245 /** 246 * @deprecated since 4.3 247 */ 248 @Deprecated 249 @CheckForNull 250 public WorkDuration.UNIT offsetUnit() { 251 return offsetUnit; 252 } 253 254 /** 255 * @deprecated since 4.3 256 */ 257 @Deprecated 258 public DefaultCharacteristic setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) { 259 this.offsetUnit = offsetUnit; 260 return this; 261 } 262 263 /** 264 * @deprecated since 4.3 265 */ 266 @Deprecated 267 public static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) { 268 if (requirementUnit != null) { 269 if (WorkUnit.DAYS.equals(requirementUnit)) { 270 return WorkDuration.UNIT.DAYS; 271 } else if (WorkUnit.HOURS.equals(requirementUnit)) { 272 return WorkDuration.UNIT.HOURS; 273 } else if (WorkUnit.MINUTES.equals(requirementUnit)) { 274 return WorkDuration.UNIT.MINUTES; 275 } 276 throw new IllegalStateException("Invalid unit : " + requirementUnit); 277 } 278 return null; 279 } 280 281 private static String fromUnit(WorkDuration.UNIT unit) { 282 if (WorkDuration.UNIT.DAYS.equals(unit)) { 283 return WorkUnit.DAYS; 284 } else if (WorkDuration.UNIT.HOURS.equals(unit)) { 285 return WorkUnit.HOURS; 286 } else if (WorkDuration.UNIT.MINUTES.equals(unit)) { 287 return WorkUnit.MINUTES; 288 } 289 throw new IllegalStateException("Invalid unit : " + unit); 290 } 291 292 public boolean isRoot() { 293 return parentId == null; 294 } 295 296 /** 297 * @deprecated since 4.3 298 */ 299 @Deprecated 300 public boolean isRequirement() { 301 return ruleKey != null; 302 } 303 304 @Override 305 public boolean equals(Object o) { 306 if (this == o) { 307 return true; 308 } 309 if (o == null || getClass() != o.getClass()) { 310 return false; 311 } 312 313 DefaultCharacteristic that = (DefaultCharacteristic) o; 314 315 if (key != null ? !key.equals(that.key) : that.key != null) { 316 return false; 317 } 318 if (ruleKey != null ? !ruleKey.equals(that.ruleKey) : that.ruleKey != null) { 319 return false; 320 } 321 322 return true; 323 } 324 325 @Override 326 public int hashCode() { 327 int result = key != null ? key.hashCode() : 0; 328 result = 31 * result + (ruleKey != null ? ruleKey.hashCode() : 0); 329 return result; 330 } 331 332 @Override 333 public String toString() { 334 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 335 } 336 337 }