001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
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    
033      private Integer trend;
034      private Integer var;
035    
036      private String ruleKey;
037      private String ruleName;
038      private String ruleCategory;
039      private String rulePriority;
040    
041      public String getMetricKey() {
042        return metricKey;
043      }
044    
045      public Measure setMetricKey(String metricKey) {
046        this.metricKey = metricKey;
047        return this;
048      }
049    
050      public String getMetricName() {
051        return metricName;
052      }
053    
054      public Measure setMetricName(String metricName) {
055        this.metricName = metricName;
056        return this;
057      }
058    
059      public Double getValue() {
060        return value;
061      }
062    
063      public Integer getIntValue() {
064        if (value==null) {
065          return null;
066        }
067        return value.intValue();
068      }
069    
070      public Measure setValue(Double value) {
071        this.value = value;
072        return this;
073      }
074    
075      public String getFormattedValue() {
076        return formattedValue;
077      }
078    
079      public String getFormattedValue(String defaultValue) {
080        if (formattedValue==null) {
081          return defaultValue;
082        }
083        return formattedValue;
084      }
085    
086      public Measure setFormattedValue(String formattedValue) {
087        this.formattedValue = formattedValue;
088        return this;
089      }
090    
091      public String getData() {
092        return data;
093      }
094    
095      public Map<String,String> getDataAsMap() {
096        return getDataAsMap(",");
097      }
098    
099      public Map<String,String> getDataAsMap(String separator) {
100        if (data==null) {
101          return null;
102        }
103        Map<String,String> map = new LinkedHashMap<String,String>();
104        String[] parts = data.split(separator);
105        for (String part : parts) {
106          String[] kv = part.split("=");
107          map.put(kv[0], kv[1]);
108        }
109        return map;
110      }
111    
112      public Measure setData(String data) {
113        this.data = data;
114        return this;
115      }
116    
117      public Integer getTrend() {
118        return trend;
119      }
120    
121      public Measure setTrend(Integer trend) {
122        this.trend = trend;
123        return this;
124      }
125    
126      public Integer getVar() {
127        return var;
128      }
129    
130      public Measure setVar(Integer var) {
131        this.var = var;
132        return this;
133      }
134    
135      public String getRuleKey() {
136        return ruleKey;
137      }
138    
139      public Measure setRuleKey(String ruleKey) {
140        this.ruleKey = ruleKey;
141        return this;
142      }
143    
144      public String getRuleName() {
145        return ruleName;
146      }
147    
148      public Measure setRuleName(String ruleName) {
149        this.ruleName = ruleName;
150        return this;
151      }
152    
153      public String getRuleCategory() {
154        return ruleCategory;
155      }
156    
157      public Measure setRuleCategory(String ruleCategory) {
158        this.ruleCategory = ruleCategory;
159        return this;
160      }
161    
162      public String getRulePriority() {
163        return rulePriority;
164      }
165    
166      public Measure setRulePriority(String rulePriority) {
167        this.rulePriority = rulePriority;
168        return this;
169      }
170    }