Example usage for org.json.simple JSONObject isEmpty

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:modelo.ApiManager.java

public static void limpiarJSONObject(JSONObject jsonObject) {

    if (!jsonObject.isEmpty()) {
        jsonObject.clear();/*from   w  w w .ja  va  2 s. c  om*/
    }

}

From source file:MyTest.ParseJson.java

private static void getDetailInfo(JSONObject jstep_detail) {
    //        System.out.println(jstep_detail);
    long id = (long) jstep_detail.get("id");
    System.out.println("id:" + id);
    String name = (String) jstep_detail.get("name");
    System.out.println("name:" + name);
    JSONArray inputs = (JSONArray) jstep_detail.get("inputs");
    if (inputs.isEmpty()) {
        System.out.println("inputs:null");

    } else {/*from  ww w.  j  a v a 2  s.  c  o  m*/
        System.out.println("inputs:");
        for (int i = 0; i < inputs.size(); i++) {
            System.out.println(inputs.get(i) + "\n");
        }
    }

    JSONArray outpus = (JSONArray) jstep_detail.get("outputs");
    if (outpus.isEmpty()) {
        System.out.println("outpus:null");
    } else {
        System.out.println("outpus:");
        for (int i = 0; i < outpus.size(); i++) {
            System.out.print(outpus.get(i) + "\n");
        }
    }

    JSONObject links = (JSONObject) jstep_detail.get("input_connections");
    if (links.isEmpty()) {
        System.out.println("input_connections:null");
    } else {
        Iterator it = links.keySet().iterator();
        System.out.println("input_connections: ");
        while (it.hasNext()) {
            Object input_link = it.next();
            System.out.println(links.get(input_link));
        }
    }
    System.out.println("-------------------------------------------------------");
}

From source file:com.github.itoshige.testrail.util.ConfigrationUtil.java

private static JSONObject getConfig() {
    try {/*w ww.ja  v  a 2  s. c  om*/
        JSONObject obj = configs.get(CONFIG_FILE);
        if (obj != null && !obj.isEmpty())
            return obj;

        JSONParser parser = new JSONParser();
        configs.putIfAbsent(CONFIG_FILE,
                (JSONObject) parser.parse(new FileReader(FilePathSearchUtil.getPath(CONFIG_FILE))));

        return configs.get(CONFIG_FILE);
    } catch (Exception e) {
        throw new TestInitializerException(String.format("%s can't be read.", CONFIG_FILE), e);
    }
}

From source file:com.conwet.silbops.connectors.comet.handlers.SubscribeResponse.java

@Override
protected void reply(HttpServletRequest req, HttpServletResponse res, PrintWriter writer,
        HttpEndPoint httpEndPoint, EndPoint connection) {
    try {// ww  w . jav  a2s  .  c  om
        String subscription = retriveParameter(req, "subscription");
        JSONObject jsonSubscription = (JSONObject) JSONValue.parseWithException(subscription);

        if (jsonSubscription.isEmpty()) {

            writeOut(writer, httpEndPoint.getEndPoint(), "subscription is empty");

        } else {

            SubscribeMsg msg = new SubscribeMsg();
            msg.setSubscription(Subscription.fromJSON(jsonSubscription));

            logger.debug("Endpoint {}, Subscribe: {}", httpEndPoint, msg);
            broker.receiveMessage(msg, connection);
            writeOut(writer, httpEndPoint.getEndPoint(), "subscribe success");
        }
    } catch (Exception ex) {
        logger.warn("subscribe exception: {}", ex.getMessage());

        try {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        } catch (IOException ex1) {
            logger.warn("subscribe reply exception: {}", ex1.getMessage());
        }
    }
}

From source file:com.cnaude.purpleirc.Utilities.UpdateChecker.java

private String updateCheck(String mode) {
    String message;/*from w  w w. java2  s .c  o  m*/
    try {
        URL url = new URL("http://h.cnaude.org:8081/job/PurpleIRC-forge/lastStableBuild/api/json");
        URLConnection conn = url.openConnection();
        conn.setReadTimeout(5000);
        conn.addRequestProperty("User-Agent", "PurpleIRC-forge Update Checker");
        conn.setDoOutput(true);
        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        final String response = reader.readLine();
        final JSONObject obj = (JSONObject) JSONValue.parse(response);
        if (obj.isEmpty()) {
            return plugin.LOG_HEADER_F + " No files found, or Feed URL is bad.";
        }

        newVersion = obj.get("number").toString();
        String downloadUrl = obj.get("url").toString();
        plugin.logDebug("newVersionTitle: " + newVersion);
        newBuild = Integer.valueOf(newVersion);
        if (newBuild > currentBuild) {
            message = plugin.LOG_HEADER_F + " Latest dev build: " + newVersion + " is out!"
                    + " You are still running build: " + currentVersion;
            message = message + plugin.LOG_HEADER_F + " Update at: " + downloadUrl;
        } else if (currentBuild > newBuild) {
            message = plugin.LOG_HEADER_F + " Dev build: " + newVersion + " | Current build: " + currentVersion;
        } else {
            message = plugin.LOG_HEADER_F + " No new version available";
        }
    } catch (IOException | NumberFormatException e) {
        message = plugin.LOG_HEADER_F + " Error checking for latest dev build: " + e.getMessage();
    }
    return message;
}

From source file:info.pancancer.arch3.utils.UtilitiesIT.java

/**
 * Test of parseJSONStr method, of class Utilities.
 *
 * @throws java.io.IOException//  www. j av a2s .c o m
 */
@Test
public void testParseJSONStr() throws IOException {
    File file = FileUtils.getFile("src", "test", "resources", "config.json");
    Utilities instance = new Utilities();
    JSONObject result = Utilities.parseJSONStr(FileUtils.readFileToString(file));
    Assert.assertTrue("parsed json is invalid", !result.isEmpty());
}

From source file:io.github.theluca98.textapi.ActionBar.java

/**
 * Constructs an {@link ActionBar} object based on JSON-formatted text.
 *
 * @param json Text to display Must be in /tellraw JSON format.
 *///w  w  w  .  ja  v  a 2  s . co  m
public ActionBar(JSONObject json) {
    Preconditions.checkNotNull(json);
    Preconditions.checkArgument(!json.isEmpty());
    this.json = json;
}

From source file:io.github.theluca98.textapi.ActionBar.java

/**
 * Changes the text to display./*from www .jav a  2 s .c  o  m*/
 *
 * @param json Text to display. Must be in /tellraw JSON format.
 */
public void setJsonText(JSONObject json) {
    Preconditions.checkNotNull(json);
    Preconditions.checkArgument(!json.isEmpty());
    this.json = json;
}

From source file:models.GeoModel.java

public String getCurrentAddress() {
    String json = GeoModel.getCurrentLocation();
    JSONParser parser = new JSONParser();

    try {/*from   ww  w  .  ja  v a 2  s .c  om*/
        // Console.WriteLn(json);
        JSONObject response = (JSONObject) parser.parse(json);

        if (!response.isEmpty()) {

            JSONObject content = (JSONObject) response.get("content");

            StringBuilder builder = new StringBuilder();

            String city = (String) content.get("city");
            String country = (String) content.get("country");
            String ip = (String) content.get("ip");
            String lat = (String) content.get("lat");
            String lng = (String) content.get("lng");
            builder.append((city == null || city == "null") ? "" : city);
            builder.append(",");
            builder.append((country == null || country == "null") ? "" : country);

            this.controller.xhsAsyncSearch(builder.toString(), 0);
            this.controller.xhsUpdateGeoPosition(builder.toString(), lat, lng);
            // Console.WriteLn("IP "+ip);
            return ip;

        }

    } catch (Exception err) {
        err.printStackTrace();

    }

    return null;
}

From source file:com.dnastack.ga4gh.impl.BeaconizeVariantImpl.java

/**
 * Parse the JSON result and look for variants having the same
 * alt as specified.//from  w  ww .j av  a  2 s.c  o  m
 *
 * @param obj The JSON reponse
 * @param alt The alt to look for
 * @return Whether or not any variant contains the alt as an alternate base
 * @throws ParseException Problems parsing the JSON
 */
private boolean parseResponseForMatchWithAlt(JSONObject obj, String alt) throws ParseException {

    if (obj.isEmpty()) {
        return false;
    }

    JSONArray vars = (JSONArray) obj.get("variants");

    for (Object var : vars) {
        JSONArray bases = (JSONArray) ((JSONObject) var).get("alternateBases");
        if (bases == null) {
            continue;
        }
        for (Object base : bases) {
            if (base.toString().equals(alt)) {
                return true;
            }
        }
    }

    return false;
}