Example usage for org.json.simple JSONArray addAll

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

Introduction

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

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.

Usage

From source file:org.pentaho.js.require.RebuildCacheCallableTest.java

@Test
public void testCall() throws Exception {
    String nullTestKey = "null";
    String arrayKey = "array";
    String objectKey = "object";
    String dupKey = "dup";

    Map<Long, Map<String, Object>> configMap = new HashMap<>();

    JSONObject object1 = new JSONObject();
    configMap.put(1L, object1);/*from  ww w  .  jav  a2s  .  com*/
    JSONArray array1 = new JSONArray();
    array1.add(1L);
    array1.add("s");
    object1.put(arrayKey, array1);
    object1.put(nullTestKey, "a");
    object1.put(objectKey, new JSONObject());
    object1.put(dupKey, "c");
    JSONObject object2 = new JSONObject();
    configMap.put(2L, object2);
    JSONArray array2 = new JSONArray();
    array2.add("2");
    array2.add(3L);
    object2.put(arrayKey, array2);
    object2.put(nullTestKey, null);
    object2.put(objectKey, new JSONObject());
    object2.put(dupKey, "e");

    JSONObject expected = new JSONObject();
    JSONArray expectedArray = new JSONArray();
    expectedArray.addAll(array1);
    expectedArray.addAll(array2);
    expected.put("bundles", new JSONObject());
    expected.put("packages", new JSONArray());
    JSONObject map = new JSONObject();
    map.put("*", new JSONObject());
    expected.put("map", map);
    expected.put(arrayKey, expectedArray);
    expected.put(nullTestKey, "a");
    expected.put(objectKey, new JSONObject());
    expected.put(dupKey, "e");
    expected.put("shim", new JSONObject());
    expected.put("paths", new JSONObject());
    JSONObject configObj = new JSONObject();
    configObj.put("service", new JSONObject());
    expected.put("config", configObj);
    String config = new RebuildCacheCallable(this.baseUrl, configMap, this.requireJsConfigurations).call();
    if (config.endsWith(";")) {
        config = config.substring(0, config.length() - 1);
    }
    Object configValue = JSONValue.parse(config);
    testEquals(expected, (JSONObject) configValue);
}

From source file:org.ScripterRon.JavaBitcoin.RpcHandler.java

/**
 * Process 'getlog' request//from www  . ja  v a  2  s.  c o m
 *
 * @return                              Response as a JSONArray
 */
private JSONArray getLog() {
    log.debug("Processing 'getlog'");
    JSONArray result = new JSONArray();
    Logger logger = Logger.getLogger("");
    Handler[] handlers = logger.getHandlers();
    for (Handler handler : handlers) {
        if (handler instanceof MemoryLogHandler) {
            result.addAll(((MemoryLogHandler) handler).getMessages());
            break;
        }
    }
    return result;
}

From source file:org.servalproject.maps.indexgenerator.IndexWriter.java

/**
 * write the index json file/*from  w w  w.  j a  v a  2s .  c om*/
 * @param outputFile the path to the output file
 * @param mapInfoList a list of MapInfo objects contained in the index
 * @return true if the file is 
 */
@SuppressWarnings("unchecked")
public static boolean writeJsonIndex(File outputFile, ArrayList<MapInfo> mapInfoList) {

    //build the json object
    JSONObject jsonObject = new JSONObject();

    jsonObject.put("version", VERSION);
    jsonObject.put("generated", System.currentTimeMillis());
    jsonObject.put("author", AUTHOR);
    jsonObject.put("DataSource", DATA_SOURCE);
    jsonObject.put("DataFormat", DATA_FORMAT);
    jsonObject.put("DataFormatInfo", DATA_FORMAT_INFO);
    jsonObject.put("DataFormatVersion", DATA_FORMAT_VERSION);
    jsonObject.put("moreInfo", MORE_INFO);

    // build the json array of objects
    JSONArray jsonArray = new JSONArray();

    jsonArray.addAll(mapInfoList);

    // add list of objects
    jsonObject.put("mapFiles", jsonArray);

    // write the file
    try {
        PrintWriter writer = new PrintWriter(outputFile);
        writer.print(jsonObject.toString());
        writer.close();
    } catch (FileNotFoundException e) {
        System.err.println("ERROR: unable to write output file. " + e.getMessage());
        return false;
    }

    return true;
}

From source file:uk.ac.susx.tag.method51.webapp.jetty.HelpfulHandler.java

public static JSONArray jsonArray(Object... args) {
    JSONArray result = new JSONArray();

    result.addAll(Arrays.asList(args));

    return result;
}

From source file:uk.ac.susx.tag.method51.webapp.jetty.HelpfulHandler.java

public static JSONArray jsonArray(Collection<?> things) {
    JSONArray result = new JSONArray();

    result.addAll(things);

    return result;
}

From source file:woto.business.PaymentService.java

public JSONArray deletePayment(JSONObject methodParam) throws ClassNotFoundException {
    JSONArray joArray = new JSONArray();
    DBConnection db = new DBConnection(true);
    try {//ww  w.  ja v  a2  s  . com

        int pay_id = Integer.parseInt("" + methodParam.get("pay_id"));

        //Get Payment detail for pay id to be deleted
        ParameterList paramList = new ParameterList();
        paramList.add("pay_id", "" + pay_id);
        JSONObject delPayment = (JSONObject) db
                .Execute("payment.logic", "GetPaymentById", paramList.toJSONArray()).iterator().next();
        int sch_id = Integer.parseInt("" + delPayment.get("sch_id"));
        int s_id = Integer.parseInt("" + delPayment.get("s_id"));

        paramList = new ParameterList();
        paramList.add("s_id", "" + s_id);
        paramList.add("sch_id", "" + sch_id);
        JSONArray paymentsFromSchId1 = db.Execute("payment.logic", "GetPaymentAfterSchedule",
                paramList.toJSONArray());

        //Delete the  payment
        paramList = new ParameterList();
        paramList.add("pay_id", "" + pay_id);
        db.Execute("payment.logic", "deletePayment", paramList.toJSONArray());

        //Get the  payment to be reshuffed. Reschuffle all schedule from deleted scheddule
        paramList = new ParameterList();
        paramList.add("s_id", "" + s_id);
        paramList.add("sch_id", "" + sch_id);
        JSONArray paymentsFromSchId = db.Execute("payment.logic", "GetPaymentAfterSchedule",
                paramList.toJSONArray());
        if (paymentsFromSchId.size() > 0) {

            //Delete all schedule from deleted pay id schedule
            db.Execute("payment.logic", "deletePaymentFromSchId", paramList.toJSONArray());

            paramList = new ParameterList();
            paramList.add("s_id", "" + s_id);
            paramList.add("sch_id", "" + sch_id);
            JSONArray paymentsFromSchId5 = db.Execute("payment.logic", "GetPaymentAfterSchedule",
                    paramList.toJSONArray());

            //REpay the amount without the deleted payid
            Iterator<JSONObject> iterator = paymentsFromSchId.iterator();
            while (iterator.hasNext()) {
                JSONObject paymentFromSchId = (JSONObject) iterator.next();

                Float f = Float.parseFloat("" + paymentFromSchId.get("amount"));
                int ramount = f.intValue();

                JSONObject payment = new JSONObject();
                payment.put("mem_id", paymentFromSchId.get("mem_id"));
                payment.put("s_id", paymentFromSchId.get("s_id"));
                payment.put("pay_date", paymentFromSchId.get("pay_date"));
                payment.put("amount", "" + ramount);
                payment.put("collector_id", paymentFromSchId.get("collector_id"));
                payment.put("created_by", paymentFromSchId.get("created_by"));
                joArray.addAll(payAmountAtEnd(db, payment));
            }
        }

        db.commit();
    } catch (Exception e) {
        db.rollback();
        throw e;
    }

    return joArray;
}

From source file:woto.business.PaymentService.java

public JSONArray payAmount(JSONObject methodParam) throws ClassNotFoundException {

    JSONArray joArray = new JSONArray();

    DBConnection db = new DBConnection(true);
    try {//from   ww w .jav a 2 s  . c o m

        int mem_id = Integer.parseInt("" + methodParam.get("mem_id"));
        int s_id = Integer.parseInt("" + methodParam.get("s_id"));
        long amount = Long.parseLong("" + methodParam.get("amount"));
        String pay_date = (String) methodParam.get("pay_date");
        int collector_id = Integer.parseInt("" + methodParam.get("collector_id"));
        int created_by = Integer.parseInt("" + getUserId());

        //Insert a new Bill for student    
        ParameterList paramList = new ParameterList();
        paramList.add("mem_id", "" + mem_id);
        paramList.add("s_id", "" + s_id);
        paramList.add("pay_date", pay_date);
        JSONArray paymentsFromDate = db.Execute("payment.logic", "getMemberPaymentFromDate",
                paramList.toJSONArray());
        if (paymentsFromDate.size() == 0) {
            joArray.addAll(payAmountAtEnd(db, methodParam));
        } else {

            //Get the list of amount pay after the min sche"select     gm_id,    substring(cast(t_date as char), 1, 10) p_date,    sum(amount) amount,    user_id from ( (select "+gmId+" gm_id,'"+ChittyUtil.ToDBDate(payDate)+"' t_date,"+amount+" amount,"+userId+" user_id,-999 trans_id) union (select gm_id,t_date,amount,user_id,p.trans_id from     payment p  inner join chitty.transaction  t ON t.trans_id = p.trans_id  where     gm_id = "+gmId+" ) ) dt group by gm_id , substring(cast(t_date as char), 1, 10) , user_id order by t_date "
            db.Execute("payment.logic", "deletePaymentFromDate", paramList.toJSONArray());

            joArray.addAll(payAmountAtEnd(db, methodParam));
            //Pay the amount payed till now.
            Iterator<JSONObject> iterator = paymentsFromDate.iterator();
            while (iterator.hasNext()) {
                JSONObject paymentFromDate = (JSONObject) iterator.next();

                Float f = Float.parseFloat("" + paymentFromDate.get("amount"));
                int ramount = f.intValue();

                JSONObject payment = new JSONObject();
                payment.put("mem_id", paymentFromDate.get("mem_id"));
                payment.put("s_id", paymentFromDate.get("s_id"));
                payment.put("pay_date", paymentFromDate.get("pay_date"));
                payment.put("amount", "" + ramount);
                payment.put("collector_id", paymentFromDate.get("collector_id"));
                payment.put("created_by", paymentFromDate.get("created_by"));
                joArray.addAll(payAmountAtEnd(db, payment));
            }

        }

        db.commit();
    } catch (Exception e) {
        db.rollback();
        throw e;
    }

    return joArray;
}