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