diff options
author | Godin <mandrikov@gmail.com> | 2010-12-13 10:20:33 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-13 10:20:33 +0000 |
commit | 44a8c358c81415c9ed69ca676619bc04f56c853b (patch) | |
tree | 2e659ea80bd260d11a6e46d7f1561ff879d99d7a /sonar-ws-client | |
parent | dd96f2f2ed190f614be82f5b889405e307703e97 (diff) | |
download | sonarqube-44a8c358c81415c9ed69ca676619bc04f56c853b.tar.gz sonarqube-44a8c358c81415c9ed69ca676619bc04f56c853b.zip |
SONAR-833: New Web Service to get history of measures (time machine)
Diffstat (limited to 'sonar-ws-client')
-rw-r--r-- | sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java | 15 | ||||
-rw-r--r-- | sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java | 25 |
2 files changed, 40 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java index e017253f783..4c68d2c3ca1 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/TimeMachineData.java @@ -7,6 +7,9 @@ import java.util.Map; public class TimeMachineData extends Model { + /** + * We use strings here in order to support measures with string value. + */ private Map<Date, List<String>> data = new HashMap<Date, List<String>>(); public Map<Date, List<String>> getData() { @@ -18,4 +21,16 @@ public class TimeMachineData extends Model { return this; } + public Double getValueAsDouble(Date date, int index) { + if (data.containsKey(date)) { + String valueStr = data.get(date).get(index); + try { + return valueStr == null ? null : Double.valueOf(valueStr); + } catch (NumberFormatException e) { + return null; + } + } + return null; + } + } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java new file mode 100644 index 00000000000..cd7fec9609f --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java @@ -0,0 +1,25 @@ +package org.sonar.wsclient.services; + +import org.junit.Test; + +import java.util.*; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +public class TimeMachineDataTest { + + @Test + public void valueAsDouble() { + Map<Date, List<String>> map = new HashMap<Date, List<String>>(); + Date date = new Date(); + map.put(date, Arrays.asList(null, "20.3", "hello")); + TimeMachineData data = new TimeMachineData().setData(map); + + assertThat(data.getValueAsDouble(date, 0), nullValue()); + assertThat(data.getValueAsDouble(date, 1), is(20.3)); + assertThat(data.getValueAsDouble(date, 2), nullValue()); + } + +} |