@@ -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 |
@@ -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; |
@@ -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()); | |||
} | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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; |