diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-20 23:18:00 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-20 23:18:00 +0000 |
commit | c365b36cf4b231555de68b193a765502d9d28bbb (patch) | |
tree | fffd4a080e5426781abc4d23b58d4dd4bdbd8e89 /sonar-gwt-api | |
parent | ea3eb66a50e49b349174b1c03e9567e79f8c6596 (diff) | |
download | sonarqube-c365b36cf4b231555de68b193a765502d9d28bbb.tar.gz sonarqube-c365b36cf4b231555de68b193a765502d9d28bbb.zip |
add JsonUtils#getAsDouble(JSONValue) to GWT API
Diffstat (limited to 'sonar-gwt-api')
-rw-r--r-- | sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java | 12 | ||||
-rw-r--r-- | sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java index b473cc37028..d3aee0fa49c 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java +++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java @@ -176,6 +176,18 @@ public final class JsonUtils { return jsonString.stringValue(); } + public static Double getAsDouble(JSONValue jsonValue) { + if (jsonValue == null) { + return null; + } + JSONNumber jsonNumber; + if ((jsonNumber = jsonValue.isNumber()) == null) { + JSONString jsonString = jsonValue.isString(); + return jsonString != null ? Double.parseDouble(jsonString.toString()) : null; + } + return jsonNumber.doubleValue(); + } + /** * @since 2.5 */ diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java index 1fddae26e76..adc79ccc582 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java @@ -31,7 +31,7 @@ public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachine> { for (int i = 0; i < size; i++) { JSONObject cellJson = JsonUtils.getArray(cells, i); JSONArray valuesJson = cellJson.get("v").isArray(); - Object[] resultValues = new Object[valuesJson.size()]; + Object[] resultValues = new Object[JsonUtils.getArraySize(valuesJson)]; for (int indexValue = 0; indexValue < JsonUtils.getArraySize(valuesJson); indexValue++) { Object value = valuesJson.get(indexValue); resultValues[indexValue] = value; |