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