Example usage for org.json.simple JSONArray add

List of usage examples for org.json.simple JSONArray add

Introduction

In this page you can find the example usage for org.json.simple JSONArray add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:net.amigocraft.mpt.command.InstallCommand.java

public static void installPackage(String id) throws MPTException {
    if (Thread.currentThread().getId() == Main.mainThreadId)
        throw new MPTException(ERROR_COLOR + "Packages may not be installed from the main thread!");
    id = id.toLowerCase();//from ww  w .j av  a2s . c om
    try {
        File file = new File(Main.plugin.getDataFolder(), "cache" + File.separator + id + ".zip");
        if (!file.exists())
            downloadPackage(id);
        if (!Main.packageStore.containsKey("packages")
                && ((JSONObject) Main.packageStore.get("packages")).containsKey(id))
            throw new MPTException(
                    ERROR_COLOR + "Cannot find package by id " + ID_COLOR + id + ERROR_COLOR + "!");
        JSONObject pack = (JSONObject) ((JSONObject) Main.packageStore.get("packages")).get(id);
        List<String> files = new ArrayList<>();
        lockStores();
        boolean success = MiscUtil.unzip(new ZipFile(file), Bukkit.getWorldContainer(), files);
        if (!KEEP_ARCHIVES)
            file.delete();
        pack.put("installed", pack.get("version").toString());
        JSONArray fileArray = new JSONArray();
        for (String str : files)
            fileArray.add(str);
        pack.put("files", fileArray);
        try {
            writePackageStore();
        } catch (IOException ex) {
            ex.printStackTrace();
            unlockStores();
            throw new MPTException(ERROR_COLOR + "Failed to write package store to disk!");
        }
        unlockStores();
        if (!success)
            throw new MPTException(
                    ERROR_COLOR + "Some files were not extracted. Use verbose logging for details.");
    } catch (IOException ex) {
        throw new MPTException(ERROR_COLOR + "Failed to access archive!");
    }
}

From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java

public static String clansToJSON(Collection<Clan> clans) {
    if (clans == null) {
        return null;
    }/*  w  w  w .j  av  a2  s .  c  o m*/

    JSONArray array = new JSONArray();

    for (Clan clan : clans) {
        array.add(clan.getID());
    }

    return array.toJSONString();
}

From source file:edu.usc.polar.CompositeNERAgreementParser.java

public static JSONArray JSONStringify(Set<String> set) {
    JSONArray tempArr = new JSONArray();
    for (String s : set) {
        tempArr.add(s);
    }//ww w .  j av a  2 s .c  om
    return tempArr;
}

From source file:eu.edisonproject.classification.main.BatchMain.java

private static void profile(String csvFile1, String csvFile2, String output) throws IOException, Exception {
    Map<String, Collection<Double>> cv = CSVFileReader.csvCompetanceToMap(csvFile1, ",", Boolean.TRUE);
    Map<String, Collection<Double>> jobVec = CSVFileReader.csvCompetanceToMap(csvFile2, ",", Boolean.TRUE);
    CosineSimilarityMatrix cosineFunction = new CosineSimilarityMatrix();

    String k1 = cv.keySet().iterator().next();
    Map<String, Double> winners = new HashMap<>();
    for (String k : jobVec.keySet()) {
        Collection<Double> j = jobVec.get(k);
        double d = cosineFunction.computeDistance(cv.get(k1), j);
        //      if (!Double.isNaN(d)) {
        winners.put(k, d);/*from w  w w  .j a v  a2s .co  m*/
        //      }
    }
    StringBuilder lines = new StringBuilder();
    ReaderFile rf = new ReaderFile(csvFile1);
    String fileHeader = rf.readFileWithN().split("\n")[0];
    String[] header = fileHeader.split(",");
    lines.append("rank").append(",");
    lines.append(fileHeader);
    lines.append("\n");

    int rank = 0;

    JSONObject cvJson = new JSONObject();
    Collection<Double> vector = cv.get(k1);
    String val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", "");
    lines.append(rank).append(",").append(k1).append(",").append(val).append("\n");
    Iterator<Double> iter = vector.iterator();
    int i = 0;
    cvJson.put(header[i++], k1);
    while (iter.hasNext()) {
        String key = header[i++];
        Double value = iter.next();
        cvJson.put(key, value);
    }
    cvJson.put("rank", rank);
    JSONArray profileJson = new JSONArray();
    profileJson.add(cvJson);
    ValueComparator bvc = new ValueComparator(winners);
    Map<String, Double> sorted_map = new TreeMap(bvc);
    sorted_map.putAll(winners);

    for (String k : sorted_map.keySet()) {
        JSONObject jobJason = new JSONObject();
        rank++;
        vector = jobVec.get(k);
        val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", "");
        lines.append(rank).append(",").append(k).append(",").append(val).append("\n");

        i = 0;
        jobJason.put(header[i++], k);
        iter = vector.iterator();
        while (iter.hasNext()) {
            String key = header[i++];
            Double value = iter.next();
            jobJason.put(key, value);
        }
        jobJason.put("rank", rank);
        profileJson.add(jobJason);
    }
    WriterFile wf = new WriterFile(output + File.separator + "result.csv");
    wf.writeFile(lines.toString());

    wf = new WriterFile(output + File.separator + "result.json");
    wf.writeFile(profileJson.toJSONString());
}

From source file:hd3gtv.mydmam.web.Privileges.java

public static JSONArray getJSONPrivileges(String[] privilegenames) {
    JSONArray ja = new JSONArray();
    for (int pos = 0; pos < privilegenames.length; pos++) {
        ja.add(privilegenames[pos]);
    }/* w  w w.j a  va 2  s  . c  o m*/
    return ja;
}

From source file:com.lifetime.util.TimeOffUtil.java

public static HttpEntity getTimeoffRequestEntity(int page, int pagesize) {
    if ((page <= 0) || (pagesize <= 0)) {
        return null;
    }/*www  .j  a v a  2 s .  co  m*/

    JSONObject jsonObject = new JSONObject();

    jsonObject.put("page", String.valueOf(page));
    jsonObject.put("pagesize", String.valueOf(pagesize));

    JSONArray columnUris = new JSONArray();

    columnUris.add("urn:replicon:time-off-list-column:time-off");
    columnUris.add("urn:replicon:time-off-list-column:time-off-type");
    columnUris.add("urn:replicon:time-off-list-column:department-of-time-off-owner");

    jsonObject.put("columnUris", columnUris);

    JSONArray sort = new JSONArray();

    JSONObject sortObject = new JSONObject();

    sortObject.put("columnUri", "urn:replicon:time-off-list-column:time-off");
    sortObject.put("isAscending", "false");

    sort.add(sortObject);

    JSONObject filter = new JSONObject();

    JSONObject leftExpression = new JSONObject();

    leftExpression.put("filterDefinitionUri", "urn:replicon:time-off-list-filter:time-off-type");

    filter.put("leftExpression", leftExpression);

    filter.put("operatorUri", "urn:replicon:filter-operator:equal");

    JSONObject value = new JSONObject();

    value.put("string", "us-pto");

    JSONObject rightExpression = new JSONObject();

    rightExpression.put("value", value);

    filter.put("rightExpression", rightExpression);

    jsonObject.put("filterExpression", filter);

    HttpEntity entity = null;

    String jsonString = jsonObject.toJSONString();

    try {
        entity = new StringEntity(jsonString);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return entity;
}

From source file:edu.usc.polar.CompositeNERAgreementParser.java

public static void CompositeNER(String doc, String args[]) {
    try {/*from  w  w  w. j a  va 2s  .c o  m*/
        String text;
        AutoDetectParser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        InputStream stream = new FileInputStream(doc);

        //   System.out.println(stream.toString());
        parser.parse(stream, handler, metadata);
        // return handler.toString();
        text = handler.toString();
        String metaValue = metadata.toString();
        System.out.println(metaValue + "Desc:: " + metadata.get("description"));

        String[] example = new String[1];
        example[0] = text;
        String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu");
        name = name.replace("\\", ".");
        Map<String, Set<String>> list = getCoreNLP(text);
        Map<String, Set<String>> list1 = getOpenNLP(text);
        Map<String, Set<String>> list2 = getNLTKRest(text);

        Set<String> NLTKRestSet = combineSets(list2);
        Set<String> coreNLPSet = combineSets(list);
        Set<String> openNLPSet = combineSets(list1);

        /* 
         System.out.println("list coreNLP"+JSONStringify(coreNLPSet).toJSONString());
         System.out.println("list openNLPSet"+openNLPSet);
         System.out.println("list NLTKRestSet"+NLTKRestSet);          
         */
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("DOI", name);
        jsonObj.put("OpenNLP", JSONStringify(openNLPSet));
        jsonObj.put("NLTKRest", JSONStringify(NLTKRestSet));
        jsonObj.put("CoreNLP", JSONStringify(coreNLPSet));

        Set<String> union = new HashSet();
        union.addAll(NLTKRestSet);
        union.addAll(coreNLPSet);
        union.addAll(openNLPSet);

        jsonObj.put("Union", JSONStringify(union));
        Set<String> intersection = new HashSet();
        intersection.addAll(union);
        intersection.retainAll(coreNLPSet);
        intersection.retainAll(openNLPSet);
        intersection.retainAll(NLTKRestSet);
        jsonObj.put("Agreement", JSONStringify(intersection));
        /*
        System.out.println(name+"\n"+openNLPSet.size()+openNLPSet.toString()+
          "\n"+coreNLPSet.size()+coreNLPSet.toString()+
          "\n"+NLTKRestSet.size()+NLTKRestSet.toArray()+
          "\n"+intersection.size()+intersection.toArray()+
          "\n"+union.size()+union.toArray());
        */

        //jsonObj.put("metadata",metaValue.replaceAll("\\s\\s+|\n|\t"," "));             

        jsonArray.add(jsonObj);
        if (intersection.size() > 0) {
            jsonAgree.add(jsonObj);
            JSONArray jArr = new JSONArray();
            jArr.add(jsonObj);
            metadata.add("CompositeNER", jArr.toJSONString());
        }

    } catch (Exception e) {
        System.out.println("ERROR : OpenNLP" + "|File Name"
                + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString());
    }
}

From source file:model.Post_store.java

public static void update_post(String title, String content, List<String> comments, List<String> UA_comments,
        int id) {
    JSONObject obj = new JSONObject();
    obj.put("title", title);
    obj.put("content", content);

    JSONArray Jcomments = new JSONArray();
    for (String i : comments) {
        Jcomments.add(i);
    }//from ww w .  j a va2s. c  o m
    obj.put("comments", comments);

    JSONArray JUA_comments = new JSONArray();
    for (String i : UA_comments) {
        JUA_comments.add(i);
    }
    obj.put("UA_comments", UA_comments);

    try (FileWriter file = new FileWriter(root + "posts/" + id + ".json");) {
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        System.out.println(e);
    }

    //System.out.print(obj);
}

From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpRollupHandlerIntegrationTest.java

public static void testHappyCaseMultiFetchHTTPRequest(List<Locator> locators, String tenantId,
        DefaultHttpClient client) throws Exception {
    HttpPost post = new HttpPost(getBatchMetricsQueryURI(tenantId));
    JSONArray metricsToGet = new JSONArray();
    for (Locator locator : locators) {
        metricsToGet.add(locator.toString());
    }// w  ww. jav a 2 s.  com
    HttpEntity entity = new StringEntity(metricsToGet.toString(), ContentType.APPLICATION_JSON);
    post.setEntity(entity);
    HttpResponse response = client.execute(post);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}

From source file:jQuery.PRIMO.Record.java

/**
 * Resolve dedup record string.//from  www  .j a v a 2  s.  c om
 *
 * @param dedupID the dedup id
 * @param request the request
 * @return a JSON array of record id's
 */
public static String resolveDedupRecord(String dedupID, HttpServletRequest request) {
    JSONArray obj = new JSONArray();

    try {

        if ((dedupID != null) && (dedupID.length() > 0)) {
            obj.addAll(Helpers.resolveDedupRecord(dedupID, request));
        }
    } catch (Exception e) {
        e.printStackTrace();
        obj.add(e.getMessage());
    }
    return obj.toJSONString();
}