001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar 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 * Sonar 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
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.wsclient.services;
021
022 import java.util.LinkedHashMap;
023 import java.util.Map;
024
025 public class Measure extends Model {
026
027 private String metricKey;
028 private String metricName;
029 private Double value;
030 private String formattedValue;
031 private String data;
032 private String characteristicKey;
033 private String characteristicName;
034
035 private Integer trend;
036 private Integer var;
037
038 private String ruleKey;
039 private String ruleName;
040 private String ruleSeverity;
041
042 /**
043 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
044 */
045 private String ruleCategory;
046
047 private Double variation1, variation2, variation3, variation4, variation5;
048
049 public String getMetricKey() {
050 return metricKey;
051 }
052
053 public Measure setMetricKey(String metricKey) {
054 this.metricKey = metricKey;
055 return this;
056 }
057
058 public String getMetricName() {
059 return metricName;
060 }
061
062 public Measure setMetricName(String metricName) {
063 this.metricName = metricName;
064 return this;
065 }
066
067 public Double getValue() {
068 return value;
069 }
070
071 public Integer getIntValue() {
072 if (value == null) {
073 return null;
074 }
075 return value.intValue();
076 }
077
078 public Measure setValue(Double value) {
079 this.value = value;
080 return this;
081 }
082
083 public String getFormattedValue() {
084 return formattedValue;
085 }
086
087 public String getFormattedValue(String defaultValue) {
088 if (formattedValue == null) {
089 return defaultValue;
090 }
091 return formattedValue;
092 }
093
094 public Measure setFormattedValue(String formattedValue) {
095 this.formattedValue = formattedValue;
096 return this;
097 }
098
099 public String getData() {
100 return data;
101 }
102
103 public Map<String, String> getDataAsMap() {
104 return getDataAsMap(",");
105 }
106
107 public Map<String, String> getDataAsMap(String separator) {
108 if (data == null) {
109 return null;
110 }
111 Map<String, String> map = new LinkedHashMap<String, String>();
112 String[] parts = data.split(separator);
113 for (String part : parts) {
114 String[] kv = part.split("=");
115 map.put(kv[0], kv[1]);
116 }
117 return map;
118 }
119
120 public Measure setData(String data) {
121 this.data = data;
122 return this;
123 }
124
125 public Integer getTrend() {
126 return trend;
127 }
128
129 public Measure setTrend(Integer trend) {
130 this.trend = trend;
131 return this;
132 }
133
134 public Integer getVar() {
135 return var;
136 }
137
138 public Measure setVar(Integer var) {
139 this.var = var;
140 return this;
141 }
142
143 public String getRuleKey() {
144 return ruleKey;
145 }
146
147 public Measure setRuleKey(String ruleKey) {
148 this.ruleKey = ruleKey;
149 return this;
150 }
151
152 public String getRuleName() {
153 return ruleName;
154 }
155
156 public Measure setRuleName(String ruleName) {
157 this.ruleName = ruleName;
158 return this;
159 }
160
161 /**
162 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
163 */
164 @Deprecated
165 public String getRuleCategory() {
166 return ruleCategory;
167 }
168
169 /**
170 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
171 */
172 @Deprecated
173 public Measure setRuleCategory(String ruleCategory) {
174 this.ruleCategory = ruleCategory;
175 return this;
176 }
177
178 /**
179 * @since 2.5
180 */
181 public Measure setRuleSeverity(String ruleSeverity) {
182 this.ruleSeverity = ruleSeverity;
183 return this;
184 }
185
186 /**
187 * @since 2.5
188 */
189 public String getRuleSeverity() {
190 return ruleSeverity;
191 }
192
193 /**
194 * @deprecated since 2.5 use {@link #getRuleSeverity()} instead. See http://jira.codehaus.org/browse/SONAR-1829
195 */
196 @Deprecated
197 public String getRulePriority() {
198 return ruleSeverity;
199 }
200
201 /**
202 * @deprecated since 2.5 use {@link #setRuleSeverity(String)} instead. See http://jira.codehaus.org/browse/SONAR-1829
203 */
204 @Deprecated
205 public Measure setRulePriority(String rulePriority) {
206 this.ruleSeverity = rulePriority;
207 return this;
208 }
209
210 public String getCharacteristicKey() {
211 return characteristicKey;
212 }
213
214 public String getCharacteristicName() {
215 return characteristicName;
216 }
217
218 public Measure setCharacteristicKey(String s) {
219 this.characteristicKey = s;
220 return this;
221 }
222
223 public Measure setCharacteristicName(String s) {
224 this.characteristicName = s;
225 return this;
226 }
227
228 /**
229 * Variation value on period 1. The value is loaded if ResourceQuery#setIncludeTrends() is set to true.
230 * @since 2.5
231 */
232 public Double getVariation1() {
233 return variation1;
234 }
235
236 /**
237 * @since 2.5
238 */
239 public Measure setVariation1(Double variation1) {
240 this.variation1 = variation1;
241 return this;
242 }
243
244 /**
245 * Variation value on period 2. The value is loaded if ResourceQuery#setIncludeTrends() is set to true.
246 * @since 2.5
247 */
248 public Double getVariation2() {
249 return variation2;
250 }
251
252 /**
253 * @since 2.5
254 */
255 public Measure setVariation2(Double variation2) {
256 this.variation2 = variation2;
257 return this;
258 }
259
260 /**
261 * Variation value on period 3. The value is loaded if ResourceQuery#setIncludeTrends() is set to true.
262 * @since 2.5
263 */
264 public Double getVariation3() {
265 return variation3;
266 }
267
268 /**
269 * @since 2.5
270 */
271 public Measure setVariation3(Double variation3) {
272 this.variation3 = variation3;
273 return this;
274 }
275
276 /**
277 * Variation value on period 4. The value is loaded if ResourceQuery#setIncludeTrends() is set to true.
278 * @since 2.5
279 */
280 public Double getVariation4() {
281 return variation4;
282 }
283
284 /**
285 * @since 2.5
286 */
287 public Measure setVariation4(Double variation4) {
288 this.variation4 = variation4;
289 return this;
290 }
291
292 /**
293 * Variation value on period 5. The value is loaded if ResourceQuery#setIncludeTrends() is set to true.
294 * @since 2.5
295 */
296 public Double getVariation5() {
297 return variation5;
298 }
299
300 /**
301 * @since 2.5
302 */
303 public Measure setVariation5(Double variation5) {
304 this.variation5 = variation5;
305 return this;
306 }
307
308 @Override
309 public String toString() {
310 return new StringBuilder().append("Measure{")
311 .append("metricKey='").append(metricKey).append('\'')
312 .append(", metricName='").append(metricName).append('\'')
313 .append(", value=").append(value)
314 .append(", formattedValue='").append(formattedValue).append('\'')
315 .append(", data='").append(data).append('\'')
316 .append(", characteristicKey='").append(characteristicKey).append('\'')
317 .append(", characteristicName='").append(characteristicName).append('\'')
318 .append(", trend=").append(trend).append(", var=").append(var)
319 .append(", ruleKey='").append(ruleKey).append('\'')
320 .append(", ruleName='").append(ruleName).append('\'')
321 .append(", ruleCategory='").append(ruleCategory).append('\'')
322 .append(", rulePriority='").append(ruleSeverity).append('\'')
323 .append('}').toString();
324 }
325 }