]> source.dussan.org Git - sonarqube.git/commitdiff
add JsonUtils#getAsDouble(JSONValue) to GWT API
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 20 Dec 2010 23:18:00 +0000 (23:18 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 20 Dec 2010 23:18:00 +0000 (23:18 +0000)
sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java

index b473cc37028ab2a5682f8657ae1cf5f417ba97b9..d3aee0fa49c19358dbaf637e397d0e96d90d2a9f 100644 (file)
@@ -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
    */
index 1fddae26e76db373b132d26d1ccb0ded943dd54d..adc79ccc5825d49c0fe9678e01be8de4add54c7b 100644 (file)
@@ -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;