Example usage for org.json.simple JSONObject containsKey

List of usage examples for org.json.simple JSONObject containsKey

Introduction

In this page you can find the example usage for org.json.simple JSONObject containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:eu.seaclouds.platform.discoverer.crawler.CloudTypes.java

private Offering generatePAASOffering(CloudHarmonyService chs, JSONObject location) {
    /* tosca lines into ArrayList */
    /* name *///  www  . j  a v a 2 s  .com
    String name = Offering.sanitizeName(chs.name + "_" + location.get("city"));

    Offering offering = new Offering(name);

    offering.setType("seaclouds.nodes.Platform." + Offering.sanitizeName(chs.name));

    /* resource type  */
    offering.addProperty("resource_type", "platform");

    /* sla */
    if (chs.sla != null) {
        offering.addProperty("availability", this.slaFormat.format(chs.sla / 100.0));
    }

    /* location */
    offering.addProperty("country", expandCountryCode((String) (location.get("country"))));
    offering.addProperty("city", expandCountryCode((String) (location.get("city"))));

    /* features */
    JSONObject feat = (JSONObject) chs.serviceFeatures;

    /* booleans */
    for (String k : this.booleans.keySet()) {
        if (feat.containsKey(k)) {
            boolean v = Boolean.parseBoolean((String) (feat.get(k)));
            offering.addProperty(this.booleans.get(k), (v ? "true" : "false"));
        }
    }

    /* supported databases and languages */
    supports("supportedDatabases", feat, offering);
    supports("supportedLanguages", feat, offering);

    /* building the tosca */
    return offering;
}

From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSyncValidator.java

private String getCluster(JSONObject validateParameters, Volume vol) {
    if ((validateParameters == null) | (vol == null)) {
        return null;
    }/*from w ww .j a  va  2s.  c  o  m*/

    String cluster = null;
    if (validateParameters.containsKey("Cluster")) {
        try {
            cluster = validateParameters.get("Cluster").toString();
        } catch (Exception e) {
            logger.error("Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return cluster;

}

From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSyncValidator.java

private Integer getCreateAfter(JSONObject validateParameters, Volume vol) {
    if ((validateParameters == null) | (vol == null)) {
        return null;
    }//from  w w  w .  j ava  2  s .  com

    Integer createAfter = null;
    if (validateParameters.containsKey("CreateAfter")) {
        try {
            createAfter = Integer.parseInt(validateParameters.get("CreateAfter").toString());
        } catch (Exception e) {
            logger.error("Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return createAfter;
}

From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotChecker.java

public String getPeriod(JSONObject eideticParameters, Volume vol) {
    if ((eideticParameters == null)) {
        return null;
    }//ww w  . j av  a2s  .co  m
    JSONObject createSnapshot = null;
    if (eideticParameters.containsKey("CreateSnapshot")) {
        createSnapshot = (JSONObject) eideticParameters.get("CreateSnapshot");
    }
    if (createSnapshot == null) {
        logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\"");
        return null;
    }

    String period = null;
    if (createSnapshot.containsKey("Interval")) {
        try {
            period = createSnapshot.get("Interval").toString();
        } catch (Exception e) {
            logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return period;
}

From source file:denkgear.DenkGear.java

private void parseJSON(String d) {
    if (d != null) {
        try {/*from   w w w  . j  a  v a2s  . co  m*/
            Object obj = parser.parse(d);
            JSONObject jsonObject = (JSONObject) obj;

            // {"eSense":{"attention":0,"meditation":0},"eegPower":{"delta":59283,"theta":8704,"lowAlpha":2683,"highAlpha":598,"lowBeta":1355,"highBeta":320,"lowGamma":117,"highGamma":5125},"poorSignalLevel":200}

            if (jsonObject.containsKey("poorSignalLevel") == true) {
                tg_signal = (Long) jsonObject.get("poorSignalLevel");

                if (signalEvent != null) {
                    try {
                        signalEvent.invoke(parent, new Object[] { (int) (long) tg_signal });
                    } catch (Exception e) {
                        System.err.println("Disabling fancyEvent()");
                        e.printStackTrace();
                        signalEvent = null;
                    }
                }
            }

            if (jsonObject.containsKey("rawEeg") == true) {
                tg_raw = (Long) jsonObject.get("rawEeg");
            }

            if (jsonObject.containsKey("blinkStrength") == true) {
                tg_blinkstrength = (Long) jsonObject.get("blinkStrength");

                if (blinkEvent != null) {
                    try {
                        blinkEvent.invoke(parent, new Object[] { (int) (long) tg_blinkstrength });
                    } catch (Exception e) {
                        System.err.println("Disabling blinkEvent()");
                        e.printStackTrace();
                        blinkEvent = null;
                    }
                }
            }

            if (jsonObject.containsKey("eSense") == true) {
                JSONObject eSense = (JSONObject) jsonObject.get("eSense");
                tg_attention = (Long) eSense.get("attention");
                eSenseTable.put("attention", (int) (long) tg_attention);
                tg_meditation = (Long) eSense.get("meditation");
                eSenseTable.put("tg_meditation", (int) (long) tg_meditation);

                if (eSenseEvent != null) {
                    try {
                        eSenseEvent.invoke(parent, new Object[] { eSenseTable });
                    } catch (Exception e) {
                        System.err.println("Disabling eSenseEvent()");
                        e.printStackTrace();
                        eSenseEvent = null;
                    }
                }

                tg_ready = true;
            } else {
                //tg_ready = false;
            }

            if (jsonObject.containsKey("eegPower") == true) {
                JSONObject eegPower = (JSONObject) jsonObject.get("eegPower");
                tg_delta = (Long) eegPower.get("delta");
                eegPowerTable.put("delta", (int) (long) tg_delta);
                tg_theta = (Long) eegPower.get("theta");
                eegPowerTable.put("theta", (int) (long) tg_theta);
                tg_lowAlpha = (Long) eegPower.get("lowAlpha");
                eegPowerTable.put("lowAlpha", (int) (long) tg_lowAlpha);
                tg_highAlpha = (Long) eegPower.get("highAlpha");
                eegPowerTable.put("highAlpha", (int) (long) tg_highAlpha);
                tg_lowBeta = (Long) eegPower.get("lowBeta");
                eegPowerTable.put("lowBeta", (int) (long) tg_lowBeta);
                tg_highBeta = (Long) eegPower.get("highBeta");
                eegPowerTable.put("highBeta", (int) (long) tg_highBeta);
                tg_lowGamma = (Long) eegPower.get("lowGamma");
                eegPowerTable.put("lowGamma", (int) (long) tg_lowGamma);
                tg_highGamma = (Long) eegPower.get("highGamma");
                eegPowerTable.put("highGamma", (int) (long) tg_highGamma);

                if (eegPowerEvent != null) {
                    try {
                        eegPowerEvent.invoke(parent, new Object[] { eegPowerTable });
                    } catch (Exception e) {
                        System.err.println("Disabling eegPowerEvent()");
                        e.printStackTrace();
                        eegPowerEvent = null;
                    }
                }
            }
        } catch (Exception e) {

        }
    }
}

From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotChecker.java

public Integer getKeep(JSONObject eideticParameters, Volume vol) {
    if ((eideticParameters == null) || (vol == null)) {
        return null;
    }/*from  w w w .j a v a 2  s.c o  m*/

    JSONObject createSnapshot = null;
    if (eideticParameters.containsKey("CreateSnapshot")) {
        createSnapshot = (JSONObject) eideticParameters.get("CreateSnapshot");
    }
    if (createSnapshot == null) {
        logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\"");
        return null;
    }

    Integer keep = null;
    if (createSnapshot.containsKey("Retain")) {
        try {
            keep = Integer.parseInt(createSnapshot.get("Retain").toString());
        } catch (Exception e) {
            logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return keep;
}

From source file:org.exfio.weave.storage.StorageContext.java

private Double parseModifiedResponse(String response) throws WeaveException {

    //Assume that modified response is JSON encoded
    JSONParser parser = new JSONParser();
    JSONObject jsonObject = null;
    try {/*  w ww  .ja v a 2  s.c o m*/
        jsonObject = (JSONObject) parser.parse(response);
        if (!jsonObject.containsKey("modified")) {
            throw new WeaveException("Invalid modified response");
        }
        return JSONUtils.toDouble(jsonObject.get("modified"));

    } catch (ParseException | ClassCastException e) {

        //Okay that didn't work how about plain text
        return Double.parseDouble(response);
    }
}

From source file:eu.riscoss.rdc.RDCGithub.java

private void parseJsonParticipation(JSONAware jv, String entity, Map<String, RiskData> values) {
    if (jv instanceof JSONObject) {
        JSONObject jo = (JSONObject) jv;
        if (jo.containsKey("all")) {
            // JSONArray ja = (JSONArray)jo.get("all"));
            ArrayList<Long> ll = (ArrayList<Long>) jo.get("all");
            ArrayList<Double> doublelist = new ArrayList<Double>();
            Long sum = 0L;/*from   ww w. java  2 s .  co  m*/
            for (Long l : ll) {
                doublelist.add(l.doubleValue());
                sum += l;
            }

            Distribution d = new Distribution();
            d.setValues(doublelist);
            //weekly commit count for the repository owner and everyone else, 52 weeks
            RiskData rd = new RiskData(GITHUB_PREFIX + "participation", entity, new Date(),
                    RiskDataType.DISTRIBUTION, d);
            values.put(rd.getId(), rd);
            rd = new RiskData(GITHUB_PREFIX + "participation_sum", entity, new Date(), RiskDataType.NUMBER,
                    sum);
            values.put(rd.getId(), rd);
        }
    }
}

From source file:com.paniclauncher.data.Instance.java

public void launch() {
    final Account account = App.settings.getAccount();
    if (account == null) {
        String[] options = { App.settings.getLocalizedString("common.ok") };
        JOptionPane.showOptionDialog(App.settings.getParent(),
                App.settings.getLocalizedString("instance.noaccount"),
                App.settings.getLocalizedString("instance.noaccountselected"), JOptionPane.DEFAULT_OPTION,
                JOptionPane.ERROR_MESSAGE, null, options, options[0]);
        App.settings.setMinecraftLaunched(false);
    } else {/*w  w  w  .  j  av a 2 s .c  om*/
        String username = account.getUsername();
        String password = account.getPassword();
        if (!account.isRemembered()) {
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            JLabel passwordLabel = new JLabel(
                    App.settings.getLocalizedString("instance.enterpassword", account.getMinecraftUsername()));
            JPasswordField passwordField = new JPasswordField();
            panel.add(passwordLabel, BorderLayout.NORTH);
            panel.add(passwordField, BorderLayout.CENTER);
            int ret = JOptionPane.showConfirmDialog(App.settings.getParent(), panel,
                    App.settings.getLocalizedString("instance.enterpasswordtitle"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (ret == JOptionPane.OK_OPTION) {
                password = new String(passwordField.getPassword());
            } else {
                App.settings.setMinecraftLaunched(false);
                return;
            }
        }
        boolean loggedIn = false;
        String url = null;
        String sess = null;
        String auth = null;
        if (!App.settings.isInOfflineMode()) {
            if (isNewLaunchMethod()) {
                String result = Utils.newLogin(username, password);
                if (result == null) {
                    loggedIn = true;
                    sess = "token:0:0";
                } else {
                    JSONParser parser = new JSONParser();
                    try {
                        Object obj = parser.parse(result);
                        JSONObject jsonObject = (JSONObject) obj;
                        if (jsonObject.containsKey("accessToken")) {
                            String accessToken = (String) jsonObject.get("accessToken");
                            JSONObject profile = (JSONObject) jsonObject.get("selectedProfile");
                            String profileID = (String) profile.get("id");
                            sess = "token:" + accessToken + ":" + profileID;
                            loggedIn = true;
                        } else {
                            auth = (String) jsonObject.get("errorMessage");
                        }
                    } catch (ParseException e1) {
                        App.settings.getConsole().logStackTrace(e1);
                    }
                }
            } else {
                try {
                    url = "https://login.minecraft.net/?user=" + URLEncoder.encode(username, "UTF-8")
                            + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=999";
                } catch (UnsupportedEncodingException e1) {
                    App.settings.getConsole().logStackTrace(e1);
                }
                auth = Utils.urlToString(url);
                if (auth == null) {
                    loggedIn = true;
                    sess = "0";
                } else {
                    if (auth.contains(":")) {
                        String[] parts = auth.split(":");
                        if (parts.length == 5) {
                            loggedIn = true;
                            sess = parts[3];
                        }
                    }
                }
            }
        } else {
            loggedIn = true;
            sess = "token:0:0";
        }
        if (!loggedIn) {
            String[] options = { App.settings.getLocalizedString("common.ok") };
            JOptionPane
                    .showOptionDialog(App.settings.getParent(),
                            "<html><center>" + App.settings.getLocalizedString("instance.errorloggingin",
                                    "<br/><br/>" + auth) + "</center></html>",
                            App.settings.getLocalizedString("instance.errorloggingintitle"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
            App.settings.setMinecraftLaunched(false);
        } else {
            final String session = sess;
            Thread launcher = new Thread() {
                public void run() {
                    try {
                        long start = System.currentTimeMillis();
                        if (App.settings.getParent() != null) {
                            App.settings.getParent().setVisible(false);
                        }
                        Process process = null;
                        if (isNewLaunchMethod()) {
                            process = NewMCLauncher.launch(account, Instance.this, session);
                        } else {
                            process = MCLauncher.launch(account, Instance.this, session);
                        }
                        App.settings.showKillMinecraft(process);
                        InputStream is = process.getInputStream();
                        InputStreamReader isr = new InputStreamReader(is);
                        BufferedReader br = new BufferedReader(isr);
                        String line;
                        while ((line = br.readLine()) != null) {
                            App.settings.getConsole().logMinecraft(line);
                        }
                        App.settings.hideKillMinecraft();
                        if (App.settings.getParent() != null) {
                            App.settings.getParent().setVisible(true);
                        }
                        long end = System.currentTimeMillis();
                        if (App.settings.isInOfflineMode()) {
                            App.settings.checkOnlineStatus();
                        }
                        App.settings.setMinecraftLaunched(false);
                        if (!App.settings.isInOfflineMode()) {
                            if (App.settings.isUpdatedFiles()) {
                                App.settings.reloadLauncherData();
                            }
                        }
                    } catch (IOException e1) {
                        App.settings.getConsole().logStackTrace(e1);
                    }
                }
            };
            launcher.start();
        }
    }
}

From source file:com.walmartlabs.mupd8.application.Config.java

@SuppressWarnings("unchecked")
private void loadAppConfig(String filename) throws Exception {
    JSONObject appJson = (JSONObject) JSONValue.parse(readWithPreprocessing(new FileReader(filename)));

    JSONObject applicationNameObject = new JSONObject();
    String applicationName = (String) appJson.get("application");
    applicationNameObject.put(applicationName, appJson);

    JSONObject mupd8 = (JSONObject) configuration.get("mupd8");
    mupd8.put("application", applicationNameObject);

    if (appJson.containsKey("performers")) {
        JSONArray performers = (JSONArray) appJson.get("performers");
        for (int i = 0; i < performers.size(); i++) {
            JSONObject json = (JSONObject) performers.get(i);

            String performer = (String) json.get("performer");
            workerJSONs.put(performer, json);
        }/*from  www  .j  a v a  2 s  .  c  o  m*/

    }
}