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.batch.internal;
022
023 import org.apache.commons.lang.StringUtils;
024 import org.apache.commons.lang.builder.ToStringBuilder;
025 import org.apache.commons.lang.builder.ToStringStyle;
026 import org.sonar.api.technicaldebt.batch.Characteristic;
027
028 import javax.annotation.CheckForNull;
029 import javax.annotation.Nullable;
030
031 import java.util.Date;
032 import java.util.List;
033
034 import static com.google.common.collect.Lists.newArrayList;
035
036 /**
037 * @deprecated since 4.3
038 */
039 @Deprecated
040 public class DefaultCharacteristic implements Characteristic {
041
042 private Integer id;
043 private String key;
044 private String name;
045 private Integer order;
046 private DefaultCharacteristic parent;
047 private DefaultCharacteristic root;
048 private List<DefaultCharacteristic> children;
049 private List<DefaultRequirement> requirements;
050
051 private Date createdAt;
052 private Date updatedAt;
053
054 public DefaultCharacteristic() {
055 this.children = newArrayList();
056 this.requirements = newArrayList();
057 }
058
059 public Integer id() {
060 return id;
061 }
062
063 public DefaultCharacteristic setId(Integer id) {
064 this.id = id;
065 return this;
066 }
067
068 public String key() {
069 return key;
070 }
071
072 public DefaultCharacteristic setKey(String key) {
073 this.key = StringUtils.trimToNull(key);
074 return this;
075 }
076
077 public String name() {
078 return name;
079 }
080
081 public DefaultCharacteristic setName(String name) {
082 this.name = name;
083 return this;
084 }
085
086 public DefaultCharacteristic setName(String s, boolean asKey) {
087 this.name = StringUtils.trimToNull(s);
088 if (asKey) {
089 this.key = StringUtils.upperCase(this.name);
090 this.key = StringUtils.replaceChars(this.key, ' ', '_');
091 }
092 return this;
093 }
094
095 @CheckForNull
096 public Integer order() {
097 return order;
098 }
099
100 public DefaultCharacteristic setOrder(@Nullable Integer order) {
101 this.order = order;
102 return this;
103 }
104
105 @CheckForNull
106 public DefaultCharacteristic parent() {
107 return parent;
108 }
109
110 public DefaultCharacteristic setParent(@Nullable DefaultCharacteristic parent) {
111 if (parent != null) {
112 this.parent = parent;
113 parent.addChild(this);
114 }
115 return this;
116 }
117
118 @CheckForNull
119 public DefaultCharacteristic root() {
120 return root;
121 }
122
123 public DefaultCharacteristic setRoot(@Nullable DefaultCharacteristic root) {
124 this.root = root;
125 return this;
126 }
127
128 public List<DefaultCharacteristic> children() {
129 return children;
130 }
131
132 private DefaultCharacteristic addChild(DefaultCharacteristic child) {
133 this.children.add(child);
134 return this;
135 }
136
137 public List<DefaultRequirement> requirements() {
138 return requirements;
139 }
140
141 public DefaultCharacteristic addRequirement(DefaultRequirement requirement) {
142 this.requirements.add(requirement);
143 return this;
144 }
145
146 public boolean isRoot() {
147 return parent == null;
148 }
149
150 public Date createdAt() {
151 return createdAt;
152 }
153
154 public DefaultCharacteristic setCreatedAt(Date createdAt) {
155 this.createdAt = createdAt;
156 return this;
157 }
158
159 @CheckForNull
160 public Date updatedAt() {
161 return updatedAt;
162 }
163
164 public DefaultCharacteristic setUpdatedAt(@Nullable Date updatedAt) {
165 this.updatedAt = updatedAt;
166 return this;
167 }
168
169 @Override
170 public String toString() {
171 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
172 }
173
174 @Override
175 public boolean equals(Object o) {
176 if (this == o) {
177 return true;
178 }
179 if (o == null || getClass() != o.getClass()) {
180 return false;
181 }
182 DefaultCharacteristic that = (DefaultCharacteristic) o;
183 return key.equals(that.key);
184 }
185
186 @Override
187 public int hashCode() {
188 return key.hashCode();
189 }
190 }