]> source.dussan.org Git - sonarqube.git/commitdiff
quality model API: simplify difference between property numeric value and text value
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 4 Oct 2010 22:01:29 +0000 (22:01 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 4 Oct 2010 22:01:29 +0000 (22:01 +0000)
sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java
sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/CharacteristicProperty.java
sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicPropertyTest.java
sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicTest.java
sonar-server/src/main/webapp/stylesheets/style.css

index fb1bac76cc41d204202e9dece278cf36484a6b7d..27b6bce4402d560c76d248030fa97b8c9347e89e 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.qualitymodel;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
@@ -31,7 +30,6 @@ import org.sonar.api.rules.Rule;
 import javax.persistence.*;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @since 2.3
@@ -254,10 +252,10 @@ public final class Characteristic implements Comparable<Characteristic> {
   }
 
   public CharacteristicProperty setProperty(String key, String value) {
-    return addProperty(CharacteristicProperty.create(key).setValue(value));
+    return addProperty(CharacteristicProperty.create(key).setTextValue(value));
   }
 
-  public CharacteristicProperty setProperty(String key, double value) {
+  public CharacteristicProperty setProperty(String key, Double value) {
     return addProperty(CharacteristicProperty.create(key).setValue(value));
   }
 
@@ -276,22 +274,20 @@ public final class Characteristic implements Comparable<Characteristic> {
     return null;
   }
 
-  public String getPropertyValueAsString(String key) {
+  public String getPropertyTextValue(String key, String defaultValue) {
     CharacteristicProperty property = getProperty(key);
-    return property != null ? property.getValue() : null;
+    String value = property != null ? property.getTextValue() : null;
+    return StringUtils.defaultIfEmpty(value, defaultValue);
   }
 
-  public Double getPropertyValueAsDouble(String key) {
+  public Double getPropertyValue(String key, Double defaultValue) {
     CharacteristicProperty property = getProperty(key);
-    return property != null ? property.getValueAsDouble() : null;
+    Double value = (property != null ? property.getValue() : null);
+    return value==null ? defaultValue : value;
   }
 
-  public Map<String,String> getProperties() {
-    Map<String,String> map = Maps.newTreeMap();
-    for (CharacteristicProperty property : properties) {
-      map.put(property.getKey(), property.getValue());
-    }
-    return map;
+  public List<CharacteristicProperty> getProperties() {
+    return properties;
   }
 
   @Override
index 287dddc22e1c5551e58441404cb77b697959aadb..911041553e4c88bf7f43b51dfd370684d566d76f 100644 (file)
@@ -74,11 +74,11 @@ public final class CharacteristicProperty {
     return this;
   }
 
-  public String getValue() {
+  public String getTextValue() {
     return textValue;
   }
 
-  public Double getValueAsDouble() {
+  public Double getValue() {
     return value;
   }
 
@@ -89,29 +89,11 @@ public final class CharacteristicProperty {
     return null;
   }
 
-  public Boolean getValueAsBoolean() {
-    if (textValue!=null) {
-      return Boolean.parseBoolean(textValue);
-    }
-    return null;
-  }
-
-  public CharacteristicProperty setValue(String s) {
+  public CharacteristicProperty setTextValue(String s) {
     this.textValue = s;
     return this;
   }
 
-  public CharacteristicProperty setValue(Boolean b) {
-    this.textValue = (b==null ? null : String.valueOf(b));
-    return this;
-  }
-
-  public CharacteristicProperty setValue(Long l) {
-    this.textValue = (l==null ? null : String.valueOf(l));
-    return this;
-  }
-
-
   public CharacteristicProperty setValue(Double d) {
     this.value = d;
     return this;
index a7b4d7365de82bca1629f93cef006f4279f76b3e..77062d8a37293c7e9b3daa3cdb569ca3c4fd2fdd 100644 (file)
@@ -28,45 +28,28 @@ import static org.junit.Assert.assertThat;
 public class CharacteristicPropertyTest {
 
   @Test
-  public void testNullValue() {
+  public void testNullValues() {
     CharacteristicProperty property = CharacteristicProperty.create("foo");
+    assertThat(property.getTextValue(), nullValue());
     assertThat(property.getValue(), nullValue());
-    assertThat(property.getValueAsDouble(), nullValue());
-    assertThat(property.getValueAsBoolean(), nullValue());
     assertThat(property.getValueAsLong(), nullValue());
   }
 
-  @Test
-  public void testBooleanValue() {
-    CharacteristicProperty property = CharacteristicProperty.create("foo");
-    property.setValue(true);
-    assertThat(property.getValue(), is("true"));//stored in the text_value column
-    assertThat(property.getValueAsDouble(), nullValue());
-    assertThat(property.getValueAsBoolean(), is(true));
-    assertThat(property.getValueAsLong(), nullValue());
-
-    property.setValue(false);
-    assertThat(property.getValue(), is("false"));
-    assertThat(property.getValueAsBoolean(), is(false));
-  }
-
   @Test
   public void testNumericValue() {
     CharacteristicProperty property = CharacteristicProperty.create("foo");
     property.setValue(3.14);
-    assertThat(property.getValueAsDouble(), is(3.14));//stored in the value column
+    assertThat(property.getValue(), is(3.14));//stored in the value column
     assertThat(property.getValueAsLong(), is(3L));
-    assertThat(property.getValue(), nullValue());
-    assertThat(property.getValueAsBoolean(), nullValue());
+    assertThat(property.getTextValue(), nullValue());
   }
 
   @Test
-  public void testStringValue() {
+  public void testTextValue() {
     CharacteristicProperty property = CharacteristicProperty.create("foo");
-    property.setValue("bar");
-    assertThat(property.getValue(), is("bar"));
-    assertThat(property.getValueAsDouble(), nullValue());
-    assertThat(property.getValueAsBoolean(), is(false));
+    property.setTextValue("bar");
+    assertThat(property.getTextValue(), is("bar"));
+    assertThat(property.getValue(), nullValue());
     assertThat(property.getValueAsLong(), nullValue());
   }
 }
index 26ddfb5bb9996a5ff959989933ec4448576d5e57..6d6a23ce5ea0c463e2f3b207186bb2d00c9bffdd 100644 (file)
@@ -31,30 +31,30 @@ public class CharacteristicTest {
 
   @Test
   public void testStringProperties() {
-    Characteristic characteristic = new Characteristic();
+    Characteristic characteristic = Characteristic.create();
     characteristic.setProperty("foo", "bar");
 
     assertThat(characteristic.getProperty("foo"), notNullValue());
-    assertThat(characteristic.getPropertyValueAsString("foo"), is("bar"));
-    assertThat(characteristic.getPropertyValueAsDouble("foo"), nullValue());
+    assertThat(characteristic.getPropertyTextValue("foo", null), is("bar"));
+    assertThat(characteristic.getPropertyValue("foo", null), nullValue());
 
     assertThat(characteristic.getProperty("unknown"), nullValue());
-    assertThat(characteristic.getPropertyValueAsString("unknown"), nullValue());
+    assertThat(characteristic.getPropertyTextValue("unknown", null), nullValue());
   }
 
   @Test
   public void testDoubleProperties() {
-    Characteristic characteristic = new Characteristic();
+    Characteristic characteristic = Characteristic.create();
     characteristic.setProperty("foo", 3.1);
 
     assertThat(characteristic.getProperty("foo"), notNullValue());
-    assertThat(characteristic.getPropertyValueAsDouble("foo"), is(3.1));
-    assertThat(characteristic.getPropertyValueAsString("foo"), nullValue());
+    assertThat(characteristic.getPropertyValue("foo", null), is(3.1));
+    assertThat(characteristic.getPropertyTextValue("foo", null), nullValue());
   }
 
   @Test
   public void addProperty() {
-    Characteristic characteristic = new Characteristic();
+    Characteristic characteristic = Characteristic.create();
     characteristic.addProperty(CharacteristicProperty.create("foo"));
 
     CharacteristicProperty property = characteristic.getProperty("foo");
@@ -70,13 +70,16 @@ public class CharacteristicTest {
   }
 
   @Test
-  public void shouldSetNameAsKey() {
-    Characteristic characteristic = new Characteristic().setName("Foo", true);
-    assertThat(characteristic.getKey(), is("FOO"));
-    assertThat(characteristic.getName(), is("Foo"));
+  public void shouldReturnDefaultValues() {
+    Characteristic characteristic = Characteristic.create();
+    characteristic.setProperty("foo", (String)null);
+    characteristic.setProperty("bar", (Double)null);
 
-    characteristic = new Characteristic().setName(null, true);
-    assertThat(characteristic.getKey(), nullValue());
-    assertThat(characteristic.getName(), nullValue());
+    assertThat(characteristic.getPropertyTextValue("foo", "foodef"), is("foodef"));
+    assertThat(characteristic.getPropertyTextValue("other", "otherdef"), is("otherdef"));
+    assertThat(characteristic.getPropertyValue("bar", 3.14), is(3.14));
+    assertThat(characteristic.getPropertyValue("other", 3.14), is(3.14));
   }
+
+  
 }
index 728031dfcf6e975a906369640b2c8a120e1e4e0c..8f82420b770274e9612ae7b4fe1a485157a32e45 100644 (file)
@@ -1425,6 +1425,8 @@ table.without-header {
   border-top: 1px solid #ddd;
 }
 table.data2 > tbody > tr {
+  border-left: 1px solid #ddd;
+  border-right: 1px solid #ddd;
 }
 table.data2 > thead > tr {
   height: 18px;