Example usage for org.json JSONArray JSONArray

List of usage examples for org.json JSONArray JSONArray

Introduction

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

Prototype

public JSONArray() 

Source Link

Document

Construct an empty JSONArray.

Usage

From source file:com.openAtlas.bundleInfo.maker.BundleMakeBooter.java

public static void main(String[] args) throws JSONException, IOException {
    //if(args.length!=2){
    //   throw new  IOException(" args to less , usage plugin_dir out_put_json_path");
    //}/*from ww  w. j  av  a2  s.  co m*/

    args = new String[2];
    args[0] = "C:\\Users\\kltz\\Desktop\\AtlasDemo\\plugin";
    args[1] = "C:\\Users\\kltz\\Desktop\\AtlasDemo\\plugin\\bundle-info.json";

    String path = args[0];
    ApkPreProcess.preProcess(path);
    String targetFile = args[1];
    File dirFile = new File(path);
    JSONArray jsonArray = new JSONArray();
    File[] files = dirFile.listFiles();
    for (File file : files) {
        if (file.getAbsolutePath().contains("libcom")) {
            PackageLite packageLit = PackageLite.parse(file.getAbsolutePath());
            jsonArray.put(packageLit.getBundleInfo());
            //            try {
            //                packageLit.getBundleInfo().toString();
            //            } catch (JSONException e) {
            //               // TODO Auto-generated catch block
            //               e.printStackTrace();
            //            }
        }

    }
    org.apache.commons.io.FileUtils.writeStringToFile(new File(targetFile), jsonArray.toString());
    System.out.println(jsonArray.toString());
}

From source file:org.seadpdt.impl.PeopleServicesImpl.java

@GET
@Path("/list/")
@Produces(MediaType.APPLICATION_JSON)//from  www .j  av a  2s. co  m
public Response getPeopleListAsArray() {
    FindIterable<Document> iter = peopleCollection.find();
    iter.projection(getBasicPersonProjection());

    MongoCursor<Document> cursor = iter.iterator();
    JSONArray array = new JSONArray();
    while (cursor.hasNext()) {
        Document next = cursor.next();
        next.put("@context", getPersonContext());
        array.put(next);
    }
    return Response.ok(array.toString()).cacheControl(control).build();
}

From source file:com.cssweb.android.view.KlineViewSingle.java

/**
 * ??//from  w  w  w  .  j  a  v  a 2s  .c  om
 * @throws JSONException 
 */
private void makeTodayData() throws JSONException {
    int l = quoteData.getJSONArray("K").length();
    if (quoteData.isNull("joTMP")) {//temp??
        newStockhandler();
        return;
    }
    if (!quoteData.getBoolean("tradeFlag")) {
        //??????
        //???0??
        return;
    }
    JSONObject tempvalue = quoteData.getJSONObject("joTMP");
    double zrsp = quoteData.getDouble("zrsp");
    period = quoteData.getString("period");
    if (period.equals("week") || period.equals("month") || period.equals("year")) {
        if (tempvalue.getString(period) != null) {
            if (tempvalue.isNull("ma") || quoteData.isNull("MA") || quoteData.isNull("K")) {
                makeTmpData();
                return;
            }
            int tp = quoteData.getInt("tp");
            if (tp == 1) {
                String date = tempvalue.getJSONObject(period).getString("date");
                if (DateTool.isSameWeekMonthYear(date, period)) {
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(1,
                            tempvalue.getJSONObject(period).getDouble("open"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                            tempvalue.getJSONObject(period).getDouble("high"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                            tempvalue.getJSONObject(period).getDouble("low"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(4, zrsp);
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                            tempvalue.getJSONObject(period).getDouble("cjsl"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                            tempvalue.getJSONObject(period).getDouble("cjje"));
                    //quoteData.getJSONArray("K").getJSONArray(l-1).put(0, ) ;
                    zrsp = tempvalue.getJSONObject(period).getDouble("close");
                }
            } else {
                int spayday = quoteData.getInt("spday");
                double cjsl = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(5);
                double cjje = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(6);
                if (spayday == 0) {//0??temp?????
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                            Math.max(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(2),
                                    tempvalue.getJSONObject(period).getDouble("high")));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                            Math.min(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(3),
                                    tempvalue.getJSONObject(period).getDouble("low")));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                            cjsl + tempvalue.getJSONObject(period).getDouble("cjsl"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                            cjje + tempvalue.getJSONObject(period).getDouble("cjje"));
                } else {
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                            Math.max(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(2),
                                    tempvalue.getJSONObject(period).getDouble("high")));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                            Math.min(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(3),
                                    tempvalue.getJSONObject(period).getDouble("low")));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                            tempvalue.getJSONObject(period).getDouble("cjsl"));
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                            tempvalue.getJSONObject(period).getDouble("cjje"));
                }
                double jrkp = tempvalue.getJSONObject(period).getDouble("open");
                if (jrkp != 0) {
                    quoteData.getJSONArray("K").getJSONArray(l - 1).put(1, jrkp);
                }
                zrsp = tempvalue.getJSONObject(period).getDouble("close");
            }
        }
    }

    String qt = quoteData.getJSONArray("K").getJSONArray(l - 1).getString(0);
    double high = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(2);
    double low = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(3);
    double zjcj = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(4);
    double cjsl = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(5);

    double summa4 = tempvalue.getJSONObject("ma").getDouble("sumMa4");
    double summa9 = tempvalue.getJSONObject("ma").getDouble("sumMa9");
    double summa19 = tempvalue.getJSONObject("ma").getDouble("sumMa19");
    double summa59 = tempvalue.getJSONObject("ma").getDouble("sumMa59");
    double sumvolma4 = tempvalue.getJSONObject("ma").getDouble("sumMavol4");
    double sumvolma9 = tempvalue.getJSONObject("ma").getDouble("sumMavol9");

    if (mainIndicatorType.toUpperCase().equals("MA") || mainIndicatorType.toUpperCase().equals("BOLL")) {
        quoteData.getJSONArray("MA").put(new JSONArray());
        quoteData.getJSONArray("MA").getJSONArray(l - 1).put(0, qt);
        double ma5 = 0;
        if (l > 4)
            ma5 = (summa4 + zjcj) / 5;
        quoteData.getJSONArray("MA").getJSONArray(l - 1).put(1, ma5);
        double ma10 = 0;
        if (l > 9)
            ma10 = (summa9 + zjcj) / 10;
        quoteData.getJSONArray("MA").getJSONArray(l - 1).put(2, ma10);
        double ma20 = 0;
        if (l > 19)
            ma20 = (summa19 + zjcj) / 20;
        quoteData.getJSONArray("MA").getJSONArray(l - 1).put(3, ma20);
        double ma60 = 0;
        if (l > 59)
            ma60 = (summa59 + zjcj) / 60;
        quoteData.getJSONArray("MA").getJSONArray(l - 1).put(4, ma60);
    }
    double mavol5 = (sumvolma4 + cjsl) / 5;
    quoteData.getJSONArray("MA").getJSONArray(l - 1).put(5, mavol5);

    double mavol10 = (sumvolma9 + cjsl) / 10;
    quoteData.getJSONArray("MA").getJSONArray(l - 1).put(6, mavol10);

    if (mainIndicatorType.equals("BOLL")) {
        quoteData.getJSONArray("BOLL").put(new JSONArray());
        double mid = 0;
        double upper = 0;
        double lower = 0;
        if (l > 25) {
            double sumClose = tempvalue.getJSONObject("boll").getDouble("sumClose");
            double sumPowClose = tempvalue.getJSONObject("boll").getDouble("sumPowClose");
            double maPow = 0;
            double temp;
            if (l > 25) {
                mid = (sumClose + zjcj) / 26;
                maPow = (sumPowClose + zjcj * zjcj) / 26;
                temp = (maPow - mid * mid);
                if (temp < 0)
                    temp = 0;
                upper = mid + 2 * Math.sqrt((temp * 26) / (26 - 1));
                lower = mid - 2 * Math.sqrt((temp * 26) / (26 - 1));
            }
        }

        quoteData.getJSONArray("BOLL").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("BOLL").getJSONArray(l - 1).put(1, mid);
        quoteData.getJSONArray("BOLL").getJSONArray(l - 1).put(2, upper);
        quoteData.getJSONArray("BOLL").getJSONArray(l - 1).put(3, lower);
    }

    if (indicatorType.equals("MACD")) {
        quoteData.getJSONArray("MACD").put(new JSONArray());
        double prevemashort = 0;
        double prevemalong = 0;
        double prevdea = 0;
        double dif = 0;
        double dea = 0;
        double macd = 0;
        double emashort = 0;
        double emalong = 0;

        prevemashort = tempvalue.getJSONObject("macd").getDouble("emaShort");
        prevemalong = tempvalue.getJSONObject("macd").getDouble("emaLong");
        prevdea = tempvalue.getJSONObject("macd").getDouble("dea");

        if (l > 1) {
            emashort = (2 * zjcj + (12 - 1) * prevemashort) / (12 + 1);
            emalong = (2 * zjcj + (26 - 1) * prevemalong) / (26 + 1);
            dif = emashort - emalong;
            dea = (2 * dif + (9 - 1) * prevdea) / (9 + 1);
            macd = (dif - dea) * 2;
        }

        quoteData.getJSONArray("MACD").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("MACD").getJSONArray(l - 1).put(1, dif);
        quoteData.getJSONArray("MACD").getJSONArray(l - 1).put(2, dea);
        quoteData.getJSONArray("MACD").getJSONArray(l - 1).put(3, macd);
    }
    if (indicatorType.equals("BIAS")) {
        quoteData.getJSONArray("BIAS").put(new JSONArray());
        double sum5 = tempvalue.getJSONObject("bias").getDouble("sum5");
        double sum11 = tempvalue.getJSONObject("bias").getDouble("sum11");
        double sum23 = tempvalue.getJSONObject("bias").getDouble("sum23");

        double bias1 = l >= 6 ? (zjcj - (sum5 + zjcj) / 6) / ((sum5 + zjcj) / 6) * 100 : 0;
        double bias2 = l >= 12 ? (zjcj - (sum11 + zjcj) / 12) / ((sum11 + zjcj) / 12) * 100 : 0;
        double bias3 = l >= 24 ? (zjcj - (sum23 + zjcj) / 24) / ((sum23 + zjcj) / 24) * 100 : 0;
        quoteData.getJSONArray("BIAS").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("BIAS").getJSONArray(l - 1).put(1, bias1);
        quoteData.getJSONArray("BIAS").getJSONArray(l - 1).put(2, bias2);
        quoteData.getJSONArray("BIAS").getJSONArray(l - 1).put(3, bias3);
    }
    if (indicatorType.equals("RSI")) {
        quoteData.getJSONArray("RSI").put(new JSONArray());

        double rsi1 = 0;
        double rsi2 = 0;
        double rsi3 = 0;

        if (l > 1 && tempvalue.has("rsi")) {
            double smaMax1 = tempvalue.getJSONObject("rsi").getDouble("smaMax1");
            double smaMax2 = tempvalue.getJSONObject("rsi").getDouble("smaMax2");
            double smaMax3 = tempvalue.getJSONObject("rsi").getDouble("smaMax3");
            double smaAbs1 = tempvalue.getJSONObject("rsi").getDouble("smaAbs1");
            double smaAbs2 = tempvalue.getJSONObject("rsi").getDouble("smaAbs2");
            double smaAbs3 = tempvalue.getJSONObject("rsi").getDouble("smaAbs3");

            double rsiMax1 = (Math.max(zjcj - zrsp, 0.0) * 1 + smaMax1 * (6 - 1)) / 6;
            double rsiAbs1 = (Math.abs(zjcj - zrsp) * 1 + smaAbs1 * (6 - 1)) / 6;
            if (rsiAbs1 == 0)
                rsi1 = 0;
            else
                rsi1 = rsiMax1 / rsiAbs1 * 100;

            double rsiMax2 = (Math.max(zjcj - zrsp, 0.0) * 1 + smaMax2 * (12 - 1)) / 12;
            double rsiAbs2 = (Math.abs(zjcj - zrsp) * 1 + smaAbs2 * (12 - 1)) / 12;
            if (rsiAbs2 == 0)
                rsi2 = 0;
            else
                rsi2 = rsiMax2 / rsiAbs2 * 100;

            double rsiMax3 = (Math.max(zjcj - zrsp, 0.0) * 1 + smaMax3 * (24 - 1)) / 24;
            double rsiAbs3 = (Math.abs(zjcj - zrsp) * 1 + smaAbs3 * (24 - 1)) / 24;
            if (rsiAbs3 == 0)
                rsi3 = 0;
            else
                rsi3 = rsiMax3 / rsiAbs3 * 100;
        }
        quoteData.getJSONArray("RSI").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("RSI").getJSONArray(l - 1).put(1, rsi1);
        quoteData.getJSONArray("RSI").getJSONArray(l - 1).put(2, rsi2);
        quoteData.getJSONArray("RSI").getJSONArray(l - 1).put(3, rsi3);
    }
    if (indicatorType.equals("KDJ")) {
        quoteData.getJSONArray("KDJ").put(new JSONArray());
        double newk = 0;
        double newd = 0;
        double newj = 0;

        if (l > 1 && tempvalue.has("kdj")) {
            double K = quoteData.getJSONArray("KDJ").getJSONArray(l - 2).getDouble(1);
            double D = quoteData.getJSONArray("KDJ").getJSONArray(l - 2).getDouble(2);
            double HHV = tempvalue.getJSONObject("kdj").getDouble("hhv");
            double LLV = tempvalue.getJSONObject("kdj").getDouble("llv");
            double nowllv = 0.0;

            if (LLV < low) // l?
                nowllv = LLV;
            else
                nowllv = low;

            double nowhhv = 0.0;
            if (HHV > high)
                nowhhv = HHV;
            else
                nowhhv = high;
            double rsv;
            if (Math.abs(nowhhv - nowllv) < 0.0001) {
                rsv = 0;
            } else {
                rsv = (zjcj - nowllv) / (nowhhv - nowllv) * 100;
            }
            newk = (rsv * 1 + K * (3 - 1)) / 3;
            newd = (newk * 1 + D * (3 - 1)) / 3;
            newj = 3 * newk - 2 * newd;
        }
        quoteData.getJSONArray("KDJ").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("KDJ").getJSONArray(l - 1).put(1, newk);
        quoteData.getJSONArray("KDJ").getJSONArray(l - 1).put(2, newd);
        quoteData.getJSONArray("KDJ").getJSONArray(l - 1).put(3, newj);
    }
    if (indicatorType.equals("CCI")) {
        quoteData.getJSONArray("CCI").put(new JSONArray());
        double CCI = 0;
        if (l > 13 && tempvalue.has("cci")) {
            JSONArray typlist = tempvalue.getJSONObject("cci").getJSONArray("typ");
            double sumTyp = 0;
            double TYP = (zjcj + high + low) / 3;
            double rit = 0;
            for (int i = 0; i < typlist.length(); i++) {
                rit = typlist.getDouble(i);
                if (i == 13)
                    break;
                sumTyp += rit;
            }
            sumTyp += TYP;
            double ma = sumTyp / 14;

            sumTyp = 0;
            for (int i = 0; i < typlist.length(); i++) {
                rit = typlist.getDouble(i);
                if (i == 13)
                    break;
                sumTyp += Math.abs(rit - ma);
            }
            sumTyp += Math.abs(TYP - ma);
            double avedev = sumTyp / 14;

            if (avedev == 0)
                CCI = 0;
            else
                CCI = (TYP - ma) / (0.015 * avedev);
        }
        quoteData.getJSONArray("CCI").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("CCI").getJSONArray(l - 1).put(1, CCI);
    }
    if (indicatorType.equals("OBV")) {
        quoteData.getJSONArray("OBV").put(new JSONArray());
        double obv = 0, maobv = 0;
        if (tempvalue.has("obv")) {
            if (zjcj > zrsp) {
                obv = tempvalue.getJSONObject("obv").getDouble("obv") + cjsl;
            }
            if (zjcj == zrsp) {
                obv = 0;
            }
            if (zjcj < zrsp) {
                obv = tempvalue.getJSONObject("obv").getDouble("obv") - cjsl;
            }
            if (l >= 29) {
                maobv = (tempvalue.getJSONObject("obv").getDouble("sumObv29") + obv) / 30;
            } else {
                maobv = 0;
            }
        }
        quoteData.getJSONArray("OBV").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("OBV").getJSONArray(l - 1).put(1, obv);
        quoteData.getJSONArray("OBV").getJSONArray(l - 1).put(2, maobv);
    }
    if (indicatorType.equals("PSY")) {
        quoteData.getJSONArray("PSY").put(new JSONArray());
        double countPsy = 0, psy = 0, psyma = 0;
        if (zjcj > zrsp) {
            countPsy = 1;
        } else {
            countPsy = 0;
        }
        if (l >= 11 && tempvalue.has("psy")) {
            countPsy += tempvalue.getJSONObject("psy").getDouble("psyCount11");
            psy = countPsy / 12 * 100;
            psyma = (tempvalue.getJSONObject("psy").getDouble("sumPsy") + psy) / 6;
        } else {
            psy = 0;
        }
        quoteData.getJSONArray("PSY").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("PSY").getJSONArray(l - 1).put(1, psy);
        quoteData.getJSONArray("PSY").getJSONArray(l - 1).put(2, psyma);
    }
    if (indicatorType.equals("ROC")) {
        quoteData.getJSONArray("ROC").put(new JSONArray());
        double roc = 0, rocma = 0;
        if (l > 12 && tempvalue.has("roc")) {
            double refClose12 = tempvalue.getJSONObject("roc").getDouble("refClose12");
            if (refClose12 == 0) {
                roc = 0;
            } else {
                roc = 100 * (zjcj - refClose12) / refClose12;
            }
            rocma = (tempvalue.getJSONObject("roc").getDouble("sumRoc") + roc) / 6;
        } else {
            roc = 0;
        }
        quoteData.getJSONArray("ROC").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("ROC").getJSONArray(l - 1).put(1, roc);
        quoteData.getJSONArray("ROC").getJSONArray(l - 1).put(2, rocma);
    }
    if (indicatorType.equals("WR")) {
        quoteData.getJSONArray("WR").put(new JSONArray());
        double wr = 0, wr2 = 0;
        if (l > 9 && tempvalue.has("wr")) {
            double llv = tempvalue.getJSONObject("wr").getDouble("llv");
            double hhv = tempvalue.getJSONObject("wr").getDouble("hhv");
            hhv = Math.max(hhv, high);
            llv = Math.min(llv, low);
            if (hhv == llv) {
                wr = 0;
            } else {
                wr = 100 * (hhv - zjcj) / (hhv - llv);
            }
        } else {
            wr = 0;
        }
        if (l > 5 && tempvalue.has("wr")) {
            double llv2 = tempvalue.getJSONObject("wr").getDouble("llv2");
            double hhv2 = tempvalue.getJSONObject("wr").getDouble("hhv2");

            hhv2 = Math.max(hhv2, high);
            llv2 = Math.min(llv2, low);
            if (hhv2 == llv2) {
                wr2 = 0;
            } else {
                wr2 = 100 * (hhv2 - zjcj) / (hhv2 - llv2);
            }
        } else {
            wr2 = 0;
        }
        quoteData.getJSONArray("WR").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("WR").getJSONArray(l - 1).put(1, wr);
        quoteData.getJSONArray("WR").getJSONArray(l - 1).put(2, wr2);
    }
    if (indicatorType.equals("VR")) {
        quoteData.getJSONArray("VR").put(new JSONArray());
        double vr = 0, vrma = 0;
        if (l >= 24 && tempvalue.has("vr")) {
            double sum1 = tempvalue.getJSONObject("vr").getDouble("sum1");
            double sum2 = tempvalue.getJSONObject("vr").getDouble("sum2");
            if (zjcj > zrsp) {
                sum1 += cjsl;
            } else {
                sum2 += cjsl;
            }
            if (sum2 == 0) {
                vr = 0;
            } else {
                vr = 100 * sum1 / sum2;
            }
        } else {
            vr = 0;
        }
        if (l >= 6)
            vrma = (tempvalue.getJSONObject("vr").getDouble("sumVr") + vr) / 6;
        quoteData.getJSONArray("VR").getJSONArray(l - 1).put(0, qt);
        quoteData.getJSONArray("VR").getJSONArray(l - 1).put(1, vr);
        quoteData.getJSONArray("VR").getJSONArray(l - 1).put(2, vrma);
    }
}

From source file:com.cssweb.android.view.KlineViewSingle.java

private void makeTmpData() throws JSONException {
    JSONObject tempvalue = quoteData.getJSONObject("joTMP");
    int l = quoteData.getJSONArray("K").length();
    double zrsp = quoteData.getDouble("zrsp");
    //      quoteData.getJSONArray("K").getJSONArray(l-1).put(1, tempvalue.getJSONObject(period).getDouble("open")) ;
    //      quoteData.getJSONArray("K").getJSONArray(l-1).put(2, tempvalue.getJSONObject(period).getDouble("high")) ;
    //      quoteData.getJSONArray("K").getJSONArray(l-1).put(3, tempvalue.getJSONObject(period).getDouble("low")) ;
    //      //quoteData.getJSONArray("K").getJSONArray(l-1).put(4, zrsp) ;
    //      quoteData.getJSONArray("K").getJSONArray(l-1).put(5, tempvalue.getJSONObject(period).getDouble("cjsl")) ;
    //      quoteData.getJSONArray("K").getJSONArray(l-1).put(6, tempvalue.getJSONObject(period).getDouble("cjje")) ;

    int tp = quoteData.getInt("tp");
    if (tp == 1) {
        String date = tempvalue.getJSONObject(period).getString("date");
        Log.i("#####date####", date + ">>>>>>>>" + DateTool.isSameWeekMonthYear(date, period));
        if (DateTool.isSameWeekMonthYear(date, period)) {
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(1,
                    tempvalue.getJSONObject(period).getDouble("open"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                    tempvalue.getJSONObject(period).getDouble("high"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                    tempvalue.getJSONObject(period).getDouble("low"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(4, zrsp);
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                    tempvalue.getJSONObject(period).getDouble("cjsl"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                    tempvalue.getJSONObject(period).getDouble("cjje"));
            //quoteData.getJSONArray("K").getJSONArray(l-1).put(0, ) ;
            zrsp = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(0);
        }/*from w  ww . j ava  2 s  .  c  o  m*/
    } else {
        int spayday = quoteData.getInt("spday");
        double cjsl = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(5);
        double cjje = quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(6);
        if (spayday == 0) {//0??temp?????
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                    Math.max(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(2),
                            tempvalue.getJSONObject(period).getDouble("high")));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                    Math.min(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(3),
                            tempvalue.getJSONObject(period).getDouble("low")));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                    cjsl + tempvalue.getJSONObject(period).getDouble("cjsl"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                    cjje + tempvalue.getJSONObject(period).getDouble("cjje"));
        } else {
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(2,
                    Math.max(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(2),
                            tempvalue.getJSONObject(period).getDouble("high")));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(3,
                    Math.min(quoteData.getJSONArray("K").getJSONArray(l - 1).getDouble(3),
                            tempvalue.getJSONObject(period).getDouble("low")));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(5,
                    tempvalue.getJSONObject(period).getDouble("cjsl"));
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(6,
                    tempvalue.getJSONObject(period).getDouble("cjje"));
        }
        double jrkp = tempvalue.getJSONObject(period).getDouble("open");
        if (jrkp != 0) {
            quoteData.getJSONArray("K").getJSONArray(l - 1).put(1, jrkp);
        }
        zrsp = tempvalue.getJSONObject(period).getDouble("close");
    }

    if (quoteData.isNull("MA") && mainIndicatorType.toUpperCase().equals("BOLL")) {
        JSONArray jMA = new JSONArray();
        jMA.put(0, 0);
        jMA.put(1, 0);
        jMA.put(2, 0);
        jMA.put(3, 0);
        jMA.put(4, 0);
        jMA.put(5, 0);
        jMA.put(6, 0);
        quoteData.put("MA", new JSONArray().put(jMA));
    }

    Log.i("#######MA#########", quoteData.isNull("MA") + ">>>>>>>>>>>");
    if (quoteData.isNull("MA")) {
        JSONArray jMA = new JSONArray();
        jMA.put(0, 0);
        jMA.put(1, 0);
        jMA.put(2, 0);
        jMA.put(3, 0);
        jMA.put(4, 0);
        jMA.put(5, 0);
        jMA.put(6, 0);
        quoteData.put(mainIndicatorType.toUpperCase(), new JSONArray().put(jMA));
    } else {
        if (quoteData.getJSONArray("MA").length() == 0) {
            JSONArray jMA = new JSONArray();
            jMA.put(0, 0);
            jMA.put(1, 0);
            jMA.put(2, 0);
            jMA.put(3, 0);
            jMA.put(4, 0);
            jMA.put(5, 0);
            jMA.put(6, 0);
            quoteData.put("MA", new JSONArray().put(jMA));
        }
    }
    Log.i("#######MA#########" + indicatorType.toUpperCase(),
            quoteData.isNull(indicatorType.toUpperCase()) + ">>>>>>>>>>>");
    if (quoteData.isNull(indicatorType.toUpperCase())) {
        JSONArray jIn = new JSONArray();
        jIn.put(0, 0);
        jIn.put(1, 0);
        jIn.put(2, 0);
        jIn.put(3, 0);
        quoteData.put(indicatorType.toUpperCase(), new JSONArray().put(jIn));
    }
    if (tempvalue.isNull("ma") && quoteData.getJSONArray("K").length() > 1) //??
        actualDataLen = quoteData.getJSONArray("K").length() - 1;
    else
        actualDataLen = quoteData.getJSONArray("K").length();
    if (actualDataLen < visualKLineCount) {
        count = actualDataLen;
    } else {
        count = visualKLineCount;
    }
    if (this.actualDataLen - this.actualPos - 1 <= this.visualKLineCount) {
        actualPos = actualDataLen - count;
    }
    Log.i("#######makeTmpData########" + actualPos, actualDataLen + ">>>>>>>>" + count);
}

From source file:com.cssweb.android.view.KlineViewSingle.java

private void newStockhandler() throws JSONException {
    //      if(!quoteData.getBoolean("tradeFlag")){
    //         return;
    //      }//from  w  ww  .  ja  v a  2 s.  c om
    Log.i("#######quoteData########", quoteData.isNull("MA") + ">>>>>>>>>>>>>>>>>" + quoteData);
    if (mainIndicatorType.toUpperCase().equals("BOLL")) {
        if (quoteData.isNull(mainIndicatorType.toUpperCase())) {
            JSONArray jMA = new JSONArray();
            jMA.put(0, 0);
            jMA.put(1, 0);
            jMA.put(2, 0);
            jMA.put(3, 0);
            jMA.put(4, 0);
            jMA.put(5, 0);
            jMA.put(6, 0);
            quoteData.put(mainIndicatorType.toUpperCase(), new JSONArray().put(jMA));
        }
    }

    if (quoteData.isNull(mainIndicatorType.toUpperCase())) {
        JSONArray jMA = new JSONArray();
        jMA.put(0, 0);
        jMA.put(1, 0);
        jMA.put(2, 0);
        jMA.put(3, 0);
        jMA.put(4, 0);
        jMA.put(5, 0);
        jMA.put(6, 0);
        quoteData.put(mainIndicatorType.toUpperCase(), new JSONArray().put(jMA));
    }

    if (quoteData.isNull(indicatorType.toUpperCase())) {
        JSONArray jIn = new JSONArray();
        jIn.put(0, 0);
        jIn.put(1, 0);
        jIn.put(2, 0);
        jIn.put(3, 0);
        quoteData.put(indicatorType.toUpperCase(), new JSONArray().put(jIn));
    }

    actualDataLen = quoteData.getJSONArray("K").length();
    if (actualDataLen < visualKLineCount) {
        count = actualDataLen;
    } else {
        count = visualKLineCount;
    }
    if (this.actualDataLen - this.actualPos - 1 <= this.visualKLineCount) {
        actualPos = actualDataLen - count;
    }
    Log.i("#######quoteData########" + actualPos, actualDataLen + ">>>>>>>>" + count);
}

From source file:ai.susi.mind.SusiReader.java

public SusiReader learn(JSONObject json) {

    // initialize temporary json objects
    JSONObject syn = json.has("synonyms") ? json.getJSONObject("synonyms") : new JSONObject();
    JSONArray fill = json.has("filler") ? json.getJSONArray("filler") : new JSONArray();
    JSONObject cat = json.has("categories") ? json.getJSONObject("categories") : new JSONObject();

    // add synonyms
    for (String canonical : syn.keySet()) {
        JSONArray a = syn.getJSONArray(canonical);
        a.forEach(synonym -> synonyms.put(((String) synonym).toLowerCase(), canonical));
    }//from w w w  .  j  a va2s  . c om

    // add filler
    fill.forEach(word -> filler.add((String) word));

    // add categories
    for (String canonical : cat.keySet()) {
        JSONArray a = cat.getJSONArray(canonical);
        a.forEach(synonym -> categories.put(((String) synonym).toLowerCase(), canonical));
    }

    return this;
}

From source file:com.grarak.kerneladiutor.utils.database.ProfileDB.java

public void putProfile(String name, LinkedHashMap<String, String> commands) {
    try {/*from w  ww .j  av  a  2s . c om*/

        JSONObject items = new JSONObject();
        items.put("name", name);

        JSONArray commandArray = new JSONArray();
        for (int i = 0; i < commands.size(); i++) {
            JSONObject item = new JSONObject();
            item.put("path", commands.keySet().toArray()[i]);
            item.put("command", commands.values().toArray()[i]);
            commandArray.put(item);
        }

        items.put("commands", commandArray);

        items.put("id", UUID.randomUUID());

        putItem(items);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.browseengine.bobo.server.protocol.BrowseJSONSerializer.java

public static String serialize(BrowseResult result) throws JSONException {
    JSONObject obj = new JSONObject();
    if (result != null) {
        obj.put("time", ((double) result.getTime()) / 1000.0);
        obj.put("hitCount", result.getNumHits());
        obj.put("totalDocs", result.getTotalDocs());

        // serialize choices
        JSONObject choices = new JSONObject();
        Set<Entry<String, FacetAccessible>> facetAccessors = result.getFacetMap().entrySet();
        for (Entry<String, FacetAccessible> entry : facetAccessors) {
            JSONObject choiceObject = new JSONObject();
            JSONArray choiceValArray = new JSONArray();

            choiceObject.put("choicelist", choiceValArray);
            int k = 0;

            String name = entry.getKey();
            FacetAccessible facets = entry.getValue();

            List<BrowseFacet> facetList = facets.getFacets();
            for (BrowseFacet facet : facetList) {
                JSONObject choice = new JSONObject();
                choice.put("val", facet.getValue());
                choice.put("hits", facet.getHitCount());
                choiceValArray.put(k++, choice);
            }//from w w w.j a  v  a2 s . co m
            choices.put(name, choiceObject);
        }
        obj.put("choices", choices);

        JSONArray hitsArray = new JSONArray();
        BrowseHit[] hits = result.getHits();
        if (hits != null && hits.length > 0) {
            for (int i = 0; i < hits.length; ++i) {
                hitsArray.put(i, serializeHits(hits[i]));
            }
        }
        obj.put("hits", hitsArray);
        // serialize documents
    }
    return obj.toString();
}

From source file:re.notifica.cordova.NotificarePlugin.java

/**
 * Fetch inbox items//from w w w . j  a v  a2s.  c  om
 * @param args
 * @param callbackContext
 */
protected void fetchInbox(JSONArray args, final CallbackContext callbackContext) {
    Log.d(TAG, "FETCHINBOX");
    if (Notificare.shared().getInboxManager() != null) {
        int size = Notificare.shared().getInboxManager().getItems().size();
        int limit = args.optInt(1, DEFAULT_LIST_SIZE);
        if (limit <= 0) {
            limit = DEFAULT_LIST_SIZE;
        }
        int skip = args.optInt(0);
        if (skip < 0) {
            skip = 0;
        }
        if (skip > size) {
            skip = size;
        }
        int end = limit + skip;
        if (end > size) {
            end = size;
        }
        List<NotificareInboxItem> items = new ArrayList<NotificareInboxItem>(
                Notificare.shared().getInboxManager().getItems()).subList(skip, end);
        JSONArray inbox = new JSONArray();
        for (NotificareInboxItem item : items) {
            try {
                JSONObject result = new JSONObject();
                result.put("itemId", item.getItemId());
                result.put("notification", item.getNotification().getNotificationId());
                result.put("message", item.getNotification().getMessage());
                result.put("status", item.getStatus());
                result.put("timestamp", dateFormatter.format(item.getTimestamp()));
                inbox.put(result);
            } catch (JSONException e) {
                // Ignore this item
                Log.w(TAG, "failed to serialize inboxitem: " + e.getMessage());
            }
        }
        if (callbackContext == null) {
            return;
        }
        JSONObject results = new JSONObject();
        try {
            results.put("inbox", inbox);
            results.put("total", size);
            results.put("unread", Notificare.shared().getInboxManager().getUnreadCount());
        } catch (JSONException e) {
            Log.w(TAG, "failed to serialize inbox: " + e.getMessage());
        }
        callbackContext.success(results);
    } else {
        if (callbackContext == null) {
            return;
        }
        callbackContext.error("No inbox manager");
    }
}

From source file:org.brickred.socialauth.provider.FourSquareImpl.java

/**
 * Gets the list of contacts of the user.
 * //from  w  w  w . j  av a2s .  c o m
 * @return List of contact objects representing Contacts. Only name and
 *         profile URL will be available
 */

@Override
public List<Contact> getContactList() throws Exception {
    LOG.info("Fetching contacts from " + CONTACTS_URL);

    Response serviceResponse;
    try {
        serviceResponse = authenticationStrategy.executeFeed(CONTACTS_URL);
    } catch (Exception e) {
        throw new SocialAuthException("Error while getting contacts from " + CONTACTS_URL, e);
    }
    if (serviceResponse.getStatus() != 200) {
        throw new SocialAuthException("Error while getting contacts from " + CONTACTS_URL + "Status : "
                + serviceResponse.getStatus());
    }
    String respStr;
    try {
        respStr = serviceResponse.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception exc) {
        throw new SocialAuthException("Failed to read response from  " + CONTACTS_URL, exc);
    }
    LOG.debug("User Contacts list in JSON " + respStr);
    JSONObject resp = new JSONObject(respStr);
    List<Contact> plist = new ArrayList<Contact>();
    JSONArray items = new JSONArray();
    if (resp.has("response")) {
        JSONObject robj = resp.getJSONObject("response");
        if (robj.has("friends")) {
            JSONObject fobj = robj.getJSONObject("friends");
            if (fobj.has("items")) {
                items = fobj.getJSONArray("items");
            }
        } else {
            throw new SocialAuthException("Failed to parse the user profile json : " + respStr);
        }
    } else {
        throw new SocialAuthException("Failed to parse the user profile json : " + respStr);
    }
    LOG.debug("Contacts Found : " + items.length());
    for (int i = 0; i < items.length(); i++) {
        JSONObject obj = items.getJSONObject(i);
        Contact c = new Contact();
        if (obj.has("firstName")) {
            c.setFirstName(obj.getString("firstName"));
        }
        if (obj.has("lastName")) {
            c.setLastName(obj.getString("lastName"));
        }
        if (obj.has("id")) {
            c.setProfileUrl(VIEW_PROFILE_URL + obj.getString("id"));
            c.setId(obj.getString("id"));
        }
        plist.add(c);
    }

    return plist;
}