2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube 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 * SonarQube 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.
21 package org.sonar.api.technicaldebt.batch.internal;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.commons.lang.builder.ToStringBuilder;
25 import org.apache.commons.lang.builder.ToStringStyle;
26 import org.sonar.api.technicaldebt.batch.Characteristic;
28 import javax.annotation.CheckForNull;
29 import javax.annotation.Nullable;
31 import java.util.Date;
32 import java.util.List;
34 import static com.google.common.collect.Lists.newArrayList;
37 * @deprecated since 4.3
40 public class DefaultCharacteristic implements Characteristic {
45 private Integer order;
46 private DefaultCharacteristic parent;
47 private DefaultCharacteristic root;
48 private List<DefaultCharacteristic> children;
49 private List<DefaultRequirement> requirements;
51 private Date createdAt;
52 private Date updatedAt;
54 public DefaultCharacteristic() {
55 this.children = newArrayList();
56 this.requirements = newArrayList();
63 public DefaultCharacteristic setId(Integer id) {
72 public DefaultCharacteristic setKey(String key) {
73 this.key = StringUtils.trimToNull(key);
77 public String name() {
81 public DefaultCharacteristic setName(String name) {
86 // TODO Replace this is a TechnicalDebtFactory class
87 public DefaultCharacteristic setName(String s, boolean asKey) {
88 this.name = StringUtils.trimToNull(s);
90 this.key = StringUtils.upperCase(this.name);
91 this.key = StringUtils.replaceChars(this.key, ' ', '_');
97 public Integer order() {
101 public DefaultCharacteristic setOrder(@Nullable Integer order) {
107 public DefaultCharacteristic parent() {
111 public DefaultCharacteristic setParent(@Nullable DefaultCharacteristic parent) {
112 if (parent != null) {
113 this.parent = parent;
114 parent.addChild(this);
120 public DefaultCharacteristic root() {
124 public DefaultCharacteristic setRoot(@Nullable DefaultCharacteristic root) {
129 public List<DefaultCharacteristic> children() {
133 private DefaultCharacteristic addChild(DefaultCharacteristic child) {
134 this.children.add(child);
138 public List<DefaultRequirement> requirements() {
142 public DefaultCharacteristic addRequirement(DefaultRequirement requirement) {
143 this.requirements.add(requirement);
147 public boolean isRoot() {
148 return parent == null;
151 public Date createdAt() {
155 public DefaultCharacteristic setCreatedAt(Date createdAt) {
156 this.createdAt = createdAt;
160 public Date updatedAt() {
164 public DefaultCharacteristic setUpdatedAt(Date updatedAt) {
165 this.updatedAt = updatedAt;
170 public String toString() {
171 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
175 public boolean equals(Object o) {
179 if (o == null || getClass() != o.getClass()) {
182 DefaultCharacteristic that = (DefaultCharacteristic) o;
183 return key.equals(that.key);
187 public int hashCode() {
188 return key.hashCode();