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