001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2013 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    
029    import javax.annotation.CheckForNull;
030    import javax.annotation.Nullable;
031    
032    /**
033     * @since 4.1
034     */
035    public class DefaultCharacteristic implements Characteristic {
036    
037      private Integer id;
038      private String key;
039      private String name;
040      private Integer order;
041      private Integer parentId;
042      private Integer rootId;
043      private RuleKey ruleKey;
044      private String function;
045      private WorkUnit factor;
046      private WorkUnit offset;
047    
048      public Integer id() {
049        return id;
050      }
051    
052      public DefaultCharacteristic setId(Integer id) {
053        this.id = id;
054        return this;
055      }
056    
057      @CheckForNull
058      public String key() {
059        return key;
060      }
061    
062      public DefaultCharacteristic setKey(@Nullable String key) {
063        this.key = key;
064        return this;
065      }
066    
067      @CheckForNull
068      public String name() {
069        return name;
070      }
071    
072      public DefaultCharacteristic setName(@Nullable String name) {
073        this.name = name;
074        return this;
075      }
076    
077      @CheckForNull
078      public Integer order() {
079        return order;
080      }
081    
082      public DefaultCharacteristic setOrder(@Nullable Integer order) {
083        this.order = order;
084        return this;
085      }
086    
087      @CheckForNull
088      public Integer parentId() {
089        return parentId;
090      }
091    
092      public DefaultCharacteristic setParentId(@Nullable Integer parentId) {
093        this.parentId = parentId;
094        return this;
095      }
096    
097      @CheckForNull
098      public Integer rootId() {
099        return rootId;
100      }
101    
102      public DefaultCharacteristic setRootId(@Nullable Integer rootId) {
103        this.rootId = rootId;
104        return this;
105      }
106    
107      @CheckForNull
108      public RuleKey ruleKey() {
109        return ruleKey;
110      }
111    
112      public DefaultCharacteristic setRuleKey(@Nullable RuleKey ruleKey) {
113        this.ruleKey = ruleKey;
114        return this;
115      }
116    
117      @CheckForNull
118      public String function() {
119        return function;
120      }
121    
122      public DefaultCharacteristic setFunction(@Nullable String function) {
123        this.function = function;
124        return this;
125      }
126    
127      @CheckForNull
128      public WorkUnit factor() {
129        return factor;
130      }
131    
132      public DefaultCharacteristic setFactor(@Nullable WorkUnit factor) {
133        this.factor = factor;
134        return this;
135      }
136    
137      @CheckForNull
138      public WorkUnit offset() {
139        return offset;
140      }
141    
142      public DefaultCharacteristic setOffset(@Nullable WorkUnit offset) {
143        this.offset = offset;
144        return this;
145      }
146    
147      public boolean isRoot() {
148        return parentId == null;
149      }
150    
151      public boolean isRequirement() {
152        return ruleKey != null;
153      }
154    
155      @Override
156      public boolean equals(Object o) {
157        if (this == o) {
158          return true;
159        }
160        if (o == null || getClass() != o.getClass()) {
161          return false;
162        }
163    
164        DefaultCharacteristic that = (DefaultCharacteristic) o;
165    
166        if (key != null ? !key.equals(that.key) : that.key != null) {
167          return false;
168        }
169        if (ruleKey != null ? !ruleKey.equals(that.ruleKey) : that.ruleKey != null) {
170          return false;
171        }
172    
173        return true;
174      }
175    
176      @Override
177      public int hashCode() {
178        int result = key != null ? key.hashCode() : 0;
179        result = 31 * result + (ruleKey != null ? ruleKey.hashCode() : 0);
180        return result;
181      }
182    
183      @Override
184      public String toString() {
185        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
186      }
187    
188    }