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