Example usage for com.google.gwt.json.client JSONNumber doubleValue

List of usage examples for com.google.gwt.json.client JSONNumber doubleValue

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONNumber doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Gets the double value this JSONNumber represents.

Usage

From source file:org.eclipse.che.ide.editor.preferences.EditorPreferencesManager.java

License:Open Source License

public Integer getNumberValueFor(EditorProperties property) {
    JSONValue jsonValue = getJsonValueFor(property);
    if (jsonValue == null) {
        return null;
    }/* www  .  j av  a2 s . c  o  m*/

    JSONNumber jsonNumber = jsonValue.isNumber();
    if (jsonNumber == null) {
        return null;
    }

    Double result = jsonNumber.doubleValue();
    return result.intValue();
}

From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java

License:Open Source License

private void setEAttributeNumberValue(EObject obj, EAttribute attribute, JSONNumber value) {
    final String numberValue = "" + value.doubleValue();

    Object newValue = EcoreUtil.createFromString(attribute.getEAttributeType(), numberValue);

    if (!attribute.isMany()) {
        obj.eSet(attribute, newValue);//from w  ww  .j av  a2s . c  o m
    } else {
        @SuppressWarnings("unchecked")
        Collection<Object> values = (Collection<Object>) obj.eGet(attribute);
        values.add(newValue);
    }
}

From source file:org.lirazs.gbackbone.client.core.data.Options.java

License:Apache License

public Options(JSONValue jsonObject) {
    JSONObject object = jsonObject.isObject();

    if (object != null) {
        for (String s : object.keySet()) {
            JSONValue jsonValue = object.get(s);
            Object value = jsonValue;

            JSONNumber number = jsonValue.isNumber();
            if (number != null) {
                if (number.toString().contains(".")) {
                    value = number.doubleValue();
                } else {
                    value = (int) number.doubleValue();
                }/* w  w w  .j  a va 2  s.  c  om*/
            }

            JSONBoolean jsonBoolean = jsonValue.isBoolean();
            if (jsonBoolean != null)
                value = jsonBoolean.booleanValue();

            JSONNull jsonNull = jsonValue.isNull();
            if (jsonNull != null)
                value = null;

            JSONString jsonString = jsonValue.isString();
            if (jsonString != null)
                value = jsonString.stringValue();

            put(s, value);
        }
    }
}

From source file:org.n52.client.Application.java

License:Open Source License

private static TimeseriesRenderingOptions createRenderingOptions(String options) {
    if (options == null) {
        return new TimeseriesRenderingOptions();
    }/*from w  w  w.  ja v  a2s.co m*/
    TimeseriesRenderingOptions tsOptions = new TimeseriesRenderingOptions();
    JSONObject tsRenderingOptions = new JSONObject(parseUntrustedJson(options));
    if (tsRenderingOptions.containsKey("color")) {
        JSONString color = tsRenderingOptions.get("color").isString();
        tsOptions.setColor(color.stringValue());
    }
    if (tsRenderingOptions.containsKey("lineWidth")) {
        JSONNumber lineWidth = tsRenderingOptions.get("lineWidth").isNumber();
        tsOptions.setLineWidth((int) lineWidth.doubleValue());
    }
    return tsOptions;
}

From source file:org.nuxeo.ecm.platform.pictures.tiles.gwt.client.model.TilingInfo.java

License:Apache License

public void parseResponse(String response) {
    if ("".equals(response)) {
        return;/*from w  ww  .ja v a2 s .  c om*/
    }
    JSONObject jsonValue = (JSONObject) JSONParser.parse(response);
    JSONObject tileInfo = (JSONObject) jsonValue.get("tileInfo");
    JSONObject originalImage = (JSONObject) jsonValue.get("originalImage");
    JSONNumber zoomFactor = (JSONNumber) tileInfo.get("zoom");
    JSONNumber widthJS = (JSONNumber) originalImage.get("width");
    JSONNumber heightJS = (JSONNumber) originalImage.get("height");
    JSONNumber xTilesJS = (JSONNumber) tileInfo.get("xtiles");
    JSONNumber yTilesJS = (JSONNumber) tileInfo.get("ytiles");
    JSONNumber maxTilesJS = (JSONNumber) tileInfo.get("maxtiles");
    JSONNumber tileWidthJS = (JSONNumber) tileInfo.get("tileWidth");
    JSONNumber tileHeightJS = (JSONNumber) tileInfo.get("tileHeight");

    zoom = zoomFactor.doubleValue();
    originalImageWidth = new Double(widthJS.doubleValue()).intValue();
    originalImageHeight = new Double(heightJS.doubleValue()).intValue();
    nbXTiles = new Double(xTilesJS.doubleValue()).intValue();
    nbYTiles = new Double(yTilesJS.doubleValue()).intValue();
    maxTiles = new Double(maxTilesJS.doubleValue()).intValue();
    tileWidth = new Double(tileWidthJS.doubleValue()).intValue();
    tileHeight = new Double(tileHeightJS.doubleValue()).intValue();

    JSONObject additionalInfo = (JSONObject) jsonValue.get("additionalInfo");
    JSONString lastModificationDateJS = (JSONString) additionalInfo.get("lastModificationDate");
    lastModificationDate = Long.parseLong(lastModificationDateJS.stringValue());

    initialized = true;
}

From source file:org.onebusaway.webapp.gwt.common.rpc.JsonLibrary.java

License:Apache License

public static Double getJsonDouble(JSONObject object, String key) {
    JSONValue value = object.get(key);/*from  w  w w. ja  va  2  s  .c  o  m*/
    if (value == null)
        return null;
    JSONNumber v = value.isNumber();
    if (v == null)
        return null;
    return new Double(v.doubleValue());
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.client.monitoring.charts.MBeanChart.java

License:Open Source License

protected double[] getJsonSlice(JSONObject json, int i) {

    double[] res = new double[json.keySet().size()];

    int counter = 0;
    for (String key : json.keySet()) {
        JSONArray values = json.get(key).isArray();
        double numValue = 0;

        if (values != null) {
            JSONNumber num = values.get(i).isNumber();
            if (num != null) {
                numValue = num.doubleValue();
            }//  w w  w  .  ja  v  a 2s. c om
        }

        res[counter++] = numValue;
    }
    return res;
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.client.monitoring.charts.MBeansChart.java

License:Open Source License

protected double[] getJsonSlice(JSONObject json, int i) {

    // assuming the response structure is the following
    // {mbean1:{theonlyattr:[values]}, mbean2:{theonlyattr:[values]}, ...}

    double[] res = new double[json.keySet().size()];

    int counter = 0;
    for (String mbean : json.keySet()) {
        JSONObject attrObject = json.get(mbean).isObject();

        double numValue = 0;
        if (attrObject != null) {
            for (String attr : attrObject.keySet()) {
                JSONArray values = attrObject.get(attr).isArray();

                if (values != null) {
                    JSONNumber num = values.get(i).isNumber();
                    if (num != null) {
                        numValue = num.doubleValue();
                    }/*from  w  w  w  . java  2s  . c om*/
                }
                break;
            }
        }

        res[counter++] = numValue;
    }
    return res;
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.json.SchedulerJSONUtils.java

License:Open Source License

protected static long getSize(JSONObject obj) throws JSONException {
    JSONValue jsonTotalValue = obj.get("size");
    if (jsonTotalValue == null) {
        throw new JSONException("Expected JSON Object with attribute total: " + obj.toString());
    }/*  w ww.  ja v a  2  s  . c o  m*/
    JSONNumber jsonTotal = jsonTotalValue.isNumber();
    if (jsonTotal == null) {
        throw new JSONException("Expected JSON number: " + jsonTotalValue.toString());
    }
    return (long) jsonTotal.doubleValue();
}

From source file:org.primordion.xholon.base.Avatar.java

License:Open Source License

/**
 * Change the value of a parameter./*w  w w .  j  av  a2s.c o m*/
 * @param name 
 * @param value 
 * @param valueRest The rest of the value, in case it contains one or more spaces.
 */
protected void param(String name, String value, String valueRest) {
    //consoleLog(name + " " + value + " " + valueRest);
    switch (name) {
    case "caption":
        switch (value) {
        case "true":
            caption = true;
            break;
        case "false":
            caption = false;
            break;
        case "null":
            captionEle = null;
            break;
        default:
            captionEle = querySelector(value);
            break;
        }
        break;
    case "view":
        switch (value) {
        case "null":
            viewEle = null;
            break;
        default:
            viewEle = querySelector(value);
            break;
        }
        break;
    case "anim":
        // ex: param anim grow 1.1;  param anim turnleft;
        outAnim[0] = "null".equals(value) ? null : value;
        outAnim[1] = "null".equals(valueRest) ? null : valueRest;
        break;
    case "debug":
        switch (value) {
        case "true":
            debug = true;
            break;
        case "false":
            debug = false;
            break;
        case "toggle":
            debug = !debug;
            break;
        default:
            break;
        }
        break;
    case "loop":
        switch (value) {
        case "true":
            loop = true;
            break;
        case "false":
            loop = false;
            break;
        case "toggle":
            loop = !loop;
            break;
        default:
            break;
        }
        break;
    case "repeat":
        switch (value) {
        case "true":
            repeat[0] = true;
            if (valueRest != null) {
                try {
                    String[] roptions = valueRest.split(",");
                    switch (roptions.length) {
                    case 1:
                        repeat[1] = Integer.parseInt(roptions[0]);
                        break;
                    case 2:
                        repeat[1] = Integer.parseInt(roptions[0]);
                        repeat[2] = Integer.parseInt(roptions[1]);
                        break;
                    default:
                        break;
                    }
                } catch (NumberFormatException e) {
                    consoleLog(e);
                }
            }
            break;
        case "false":
            repeat[0] = false;
            break;
        case "toggle":
            repeat[0] = !((boolean) repeat[0]);
            break;
        default:
            break;
        }
        break;
    case "transcript":
        switch (value) {
        case "true":
            transcript = true;
            break;
        case "false":
            transcript = false;
            break;
        case "toggle":
            transcript = !transcript;
            break;
        default:
            break;
        }
        break;
    case "speech":
        switch (value) {
        case "true":
            speech = true;
            break;
        case "false":
            speech = false;
            break;
        case "toggle":
            speech = !speech;
            break;
        default:
            if (value.charAt(0) == '{') {
                // parse this JSON string, and extract the values
                // ex: {"lang":"en-US", "voice":"Google UK English Female", "volume":1.0, "rate":1.2, "pitch":1.0}
                speech = true;
                try {
                    if (valueRest == null) {
                        valueRest = "";
                    }
                    JSONObject json = JSONParser.parseStrict(value + valueRest).isObject();
                    if (json != null) {
                        if (json.containsKey("lang")) {
                            JSONString str = json.get("lang").isString();
                            if (str != null) {
                                this.ssuLang = str.stringValue();
                            }
                        }
                        if (json.containsKey("voice")) {
                            JSONString str = json.get("voice").isString();
                            if (str != null) {
                                this.ssuVoice = findVoice(str.stringValue());
                            }
                        }
                        if (json.containsKey("volume")) {
                            JSONNumber num = json.get("volume").isNumber();
                            if (num != null) {
                                this.ssuVolume = (float) num.doubleValue();
                            }
                        }
                        if (json.containsKey("rate")) {
                            JSONNumber num = json.get("rate").isNumber();
                            if (num != null) {
                                this.ssuRate = (float) num.doubleValue();
                            }
                        }
                        if (json.containsKey("pitch")) {
                            JSONNumber num = json.get("pitch").isNumber();
                            if (num != null) {
                                this.ssuPitch = (float) num.doubleValue();
                            }
                        }
                    }
                } catch (JSONException e) {
                    consoleLog(e);
                }
            }
            break;
        }
        if (speech) {
            if (!isSpeechSupported()) {
                // this browser does not support speech, so disable it
                consoleLog("this browser does not support speech");
                speech = false;
            }
        }
        break;
    case "meteor":
        switch (value) {
        case "true":
            meteor = true;
            break;
        case "false":
            meteor = false;
            break;
        default:
            break;
        }
        break;
    case "meteormove":
        switch (value) {
        case "true":
            meteormove = true;
            break;
        case "false":
            meteormove = false;
            break;
        default:
            break;
        }
        break;
    case "meteorattr":
        this.makeMeteorAttr(value);
        break;
    case "meteor+move": // this is a shortcut
        switch (value) {
        case "true":
            meteor = true;
            meteormove = true;
            break;
        case "false":
            meteor = false;
            meteormove = false;
            break;
        default:
            break;
        }
        break;
    case "chatbot":
        switch (value) {
        case "true":
            contextNode.appendChild("Chatbot", null, "org.primordion.xholon.base.Chatbot");
            this.chatbot = contextNode.getLastChild();
            if ((this.chatbot != null) && ("Chatbot".equals(this.chatbot.getXhcName()))) {
                this.chatbot.postConfigure();
            }
            this.chatbot.removeChild();
            break;
        case "false":
            chatbot = null;
            break;
        default:
            break;
        }
        break;
    case "takenotes":
        switch (value) {
        case "true":
            takenotes = true;
            break;
        case "false":
            takenotes = false;
            break;
        default:
            break;
        }
        break;
    case "shouldstep":
        /* whether or not the system Avatar's act() method should be called each time step, if it's invisible
         * example: (Story Template - system avatar - stay invisible, go inside Home, lead book Last..., move to School)
         * var ava = xh.avatar();
         * ava.action("param shouldstep true;enter;enter city;enter home;lead Last;next school;");
         */
        switch (value) {
        case "true":
            app.setShouldStepAvatar(true);
            break;
        case "false":
            app.setShouldStepAvatar(false);
            break;
        default:
            break;
        }
        break;
    case "recipebook":
        /**
         * param recipebook RecipeService-MinecraftStyleRecipeBook-Island;
         * param recipebook MinecraftStyleRecipeBook-Island;
         * param recipebook Island;
         * param recipebook JsonRulesEngineRecipeBook-Island;
         */
        String rbname = null;
        String[] rbnameArr = value.split("-");
        switch (rbnameArr.length) {
        case 1:
            rbname = RB_DEFAULT_SERVICE_NAME + RB_SEPARATOR + RB_DEFAULT_STYLE_NAME + RB_SEPARATOR + value;
            break;
        case 2:
            rbname = RB_DEFAULT_SERVICE_NAME + RB_SEPARATOR + value;
            break;
        case 3:
            rbname = value;
            break;
        default:
            break;
        }
        if (rbname != null) {
            IXholon rserv = this.getService("RecipeService");
            if (rserv != null) {
                IMessage rmsg = rserv.sendSyncMessage(IRecipe.SIG_GET_RECIPE_BOOK_REQ, rbname, this);
                this.recipebook[0] = rbname;
                this.recipebook[1] = rmsg.getData();
            }
        }
        break;
    case "setCtxtOnselect":
        switch (value) {
        case "true":
            setCtxtOnselect = true;
            break;
        case "false":
            setCtxtOnselect = false;
            break;
        default:
            break;
        }
        break;
    case "currentActions":
        switch (value) {
        case "true":
            configureCurrentActions(true);
            break;
        case "false":
            configureCurrentActions(false);
            break;
        default:
            break;
        }
        break;
    case "subtrees":
        if ("true".equals(value)) {
            if (valueRest == null) {
                this.subtrees(SUBTREES_DEFAULT_NAMES);
            } else {
                this.subtrees(valueRest);
            }
        } else { // "false"
            this.subtrees(null);
        }
        break;
    case "actTimeStep":
        // this value must be an Integer
        try {
            this.actTimeStep = Integer.parseInt(value);
            if (this.actTimeStep < 1) {
                // value is relative rather than absolute
                this.actTimeStep = app.getTimeStep() - this.actTimeStep;
            }
        } catch (NumberFormatException e) {
            consoleLog(e);
        }
        break;
    default:
        break;
    }
}