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