Package org.json.simple

Examples of org.json.simple.JSONArray


    public void path() throws Exception {
        int count1 = 5;
        for (int i = 0; i < count1; i++) {
            mk.commit("/", "+\"a" + i + "\" : {}", null, null);
        }
        JSONArray array = parseJSONArray(mk.getRevisionHistory(0, -1, "/"));
        assertEquals(count1 + 1, array.size());


        int count2 = 5;
        for (int i = 0; i < count2; i++) {
            mk.commit("/a1", "+\"b" + i + "\" : {}", null, null);
        }
        array = parseJSONArray(mk.getRevisionHistory(0, -1, "/"));
        assertEquals(count1 + 1 + count2, array.size());

        array = parseJSONArray(mk.getRevisionHistory(0, -1, "/a1"));
        assertEquals(count2 + 1, array.size());
    }
View Full Code Here


        long since1 = System.currentTimeMillis();
        int count1 = 6;
        for (int i = 0; i < count1; i++) {
            mk.commit("/", "+\"a" + i + "\" : {}", null, null);
        }
        JSONArray array = parseJSONArray(mk.getRevisionHistory(since1, -1, "/"));
        assertEquals(count1, array.size());

        Thread.sleep(100);

        long since2 = System.currentTimeMillis();
        int count2 = 4;
        for (int i = 0; i < count2; i++) {
            mk.commit("/", "+\"b" + i + "\" : {}", null, null);
        }
        array = parseJSONArray(mk.getRevisionHistory(since2, -1, "/"));
        assertEquals(count2, array.size());

        array = parseJSONArray(mk.getRevisionHistory(since1, -1, "/"));
        assertEquals(count1 + count2, array.size());
    }
View Full Code Here

    JSONObject json = new JSONObject();
    try {
      // CPU utilization
      cpuinfo = sigar.getCpuInfoList();
      cpuPerc = sigar.getCpuPercList();
      JSONArray cpuList = new JSONArray();
      for (int i = 0; i < cpuinfo.length; i++) {
        JSONObject cpuMap = new JSONObject();
        cpuMap.putAll(cpuinfo[i].toMap());
        cpuMap.put("combined", cpuPerc[i].getCombined());
        cpuMap.put("user", cpuPerc[i].getUser());
        cpuMap.put("sys", cpuPerc[i].getSys());
        cpuMap.put("idle", cpuPerc[i].getIdle());
        cpuMap.put("wait", cpuPerc[i].getWait());
        cpuMap.put("nice", cpuPerc[i].getNice());
        cpuMap.put("irq", cpuPerc[i].getIrq());
        cpuList.add(cpuMap);
      }
      sigar.getCpuPerc();
      json.put("cpu", cpuList);
     
      // Uptime
      uptime = sigar.getUptime();
      json.put("uptime", uptime.getUptime());
     
      // Load Average
      loadavg = sigar.getLoadAverage();
      JSONArray load = new JSONArray();
      load.add(loadavg[0]);
      load.add(loadavg[1]);
      load.add(loadavg[2]);
      json.put("loadavg", load);

      // Memory Utilization
      mem = sigar.getMem();
      JSONObject memMap = new JSONObject();
      memMap.putAll(mem.toMap());
      json.put("memory", memMap);
     
      // Network Utilization
      netIf = sigar.getNetInterfaceList();
      JSONArray netInterfaces = new JSONArray();
      for (int i = 0; i < netIf.length; i++) {
        NetInterfaceStat net = new NetInterfaceStat();
        net = sigar.getNetInterfaceStat(netIf[i]);
        JSONObject netMap = new JSONObject();
        netMap.putAll(net.toMap());
        if(previousNetworkStats.containsKey(netIf[i])) {
          JSONObject deltaMap = previousNetworkStats.get(netIf[i]);
          deltaMap.put("RxBytes", Long.parseLong(netMap.get("RxBytes").toString()) - Long.parseLong(deltaMap.get("RxBytes").toString()));
          deltaMap.put("RxDropped", Long.parseLong(netMap.get("RxDropped").toString()) - Long.parseLong(deltaMap.get("RxDropped").toString()));
          deltaMap.put("RxErrors", Long.parseLong(netMap.get("RxErrors").toString()) - Long.parseLong(deltaMap.get("RxErrors").toString()));
          deltaMap.put("RxPackets", Long.parseLong(netMap.get("RxPackets").toString()) - Long.parseLong(deltaMap.get("RxPackets").toString()));
          deltaMap.put("TxBytes", Long.parseLong(netMap.get("TxBytes").toString()) - Long.parseLong(deltaMap.get("TxBytes").toString()));
          deltaMap.put("TxCollisions", Long.parseLong(netMap.get("TxCollisions").toString()) - Long.parseLong(deltaMap.get("TxCollisions").toString()));
          deltaMap.put("TxErrors", Long.parseLong(netMap.get("TxErrors").toString()) - Long.parseLong(deltaMap.get("TxErrors").toString()));
          deltaMap.put("TxPackets", Long.parseLong(netMap.get("TxPackets").toString()) - Long.parseLong(deltaMap.get("TxPackets").toString()));
          netInterfaces.add(deltaMap);
          skip = false;
        } else {
          netInterfaces.add(netMap);
          skip = true;
        }
        previousNetworkStats.put(netIf[i], netMap);
      }
      json.put("network", netInterfaces);

      // Filesystem Utilization
      fs = sigar.getFileSystemList();
      JSONArray fsList = new JSONArray();
      for (int i = 0; i < fs.length; i++) {
        FileSystemUsage usage = sigar.getFileSystemUsage(fs[i].getDirName());
        JSONObject fsMap = new JSONObject();
        fsMap.putAll(fs[i].toMap());
        fsMap.put("ReadBytes", usage.getDiskReadBytes());
        fsMap.put("Reads", usage.getDiskReads());
        fsMap.put("WriteBytes", usage.getDiskWriteBytes());
        fsMap.put("Writes", usage.getDiskWrites());
        if(previousDiskStats.containsKey(fs[i].getDevName())) {
          JSONObject deltaMap = previousDiskStats.get(fs[i].getDevName());
          deltaMap.put("ReadBytes", usage.getDiskReadBytes() - (Long) deltaMap.get("ReadBytes"));
          deltaMap.put("Reads", usage.getDiskReads() - (Long) deltaMap.get("Reads"));
          deltaMap.put("WriteBytes", usage.getDiskWriteBytes() - (Long) deltaMap.get("WriteBytes"));
          deltaMap.put("Writes", usage.getDiskWrites() - (Long) deltaMap.get("Writes"));
          deltaMap.putAll(fs[i].toMap());
          fsList.add(deltaMap);
          skip = false;
        } else {
          fsList.add(fsMap);
          skip = true;
        }
        previousDiskStats.put(fs[i].getDevName(), fsMap);         
      }
      json.put("disk", fsList);
View Full Code Here

  public ParametersBean(JSONObject json) throws ParseException {
    name=(String) json.get("name");
    type=(String) json.get("type");
    if(json.containsKey("value")) {
      if(json.get("value").getClass()==JSONArray.class) {
        JSONArray ja = (JSONArray) json.get("value");
        Collection<String> c = new HashSet<String>();
        for(int i = 0; i < ja.size(); i++) {
          c.add((String) ja.get(i));
        }
        this.value = c;
      } else {
        Collection<String> c = new HashSet<String>();
        c.add((String)json.get("value"));
        this.value = c;
      }       
    }
    if(json.containsKey("label")) {
      label=(String) json.get("label");
    } else {
      label=(String) json.get("name");
    }
    if(json.get("type").toString().intern()=="custom".intern()) {
      control=(String) json.get("control");
    }
    if(json.containsKey("callback")) {
      callback=(String) json.get("callback");
    }
    if(json.containsKey("options")) {
      JSONArray aj = (JSONArray) json.get("options");
      options = new OptionBean[aj.size()];
      for(int i=0;i<aj.size();i++) {
        OptionBean o = new OptionBean((JSONObject) aj.get(i));
        options[i]=o;
      }
    }
    if(json.containsKey("edit")) {
      if(json.get("edit").getClass().equals(String.class)) {
View Full Code Here

    JSONObject json = new JSONObject();
    try {
      json.put("name",this.name);
      json.put("type",this.type);
      if(this.value!=null) {
        JSONArray ja = new JSONArray();
        for(String s : this.value) {
          ja.add(s);
        }
        json.put("value", ja);
      }
      if(control!=null) {
        json.put("control",this.control);
      }
      json.put("label",this.label);
      json.put("edit",this.edit);
      if(this.callback!=null) {
        json.put("callback", callback);
      }
      if(options!=null) {
        JSONArray ja = new JSONArray();
        for(int i=0;i<options.length;i++) {
          ja.add(this.options[i].deserialize());         
        }
        json.put("options", ja);
      }
    } catch (Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
View Full Code Here

      this.owner= (String) json.get("owner");
      this.name= (String) json.get("name");
      this.permissionType= (String) json.get("permissionType");
      int size = ((JSONArray) json.get("pages")).size();
      PagesBean[] pages = new PagesBean[size];
      JSONArray pagesArray = (JSONArray) json.get("pages");
      for(int i=0;i<size;i++) {
        pages[i] = new PagesBean((JSONObject) pagesArray.get(i));
      }
      this.pages=pages;
    } catch (Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
View Full Code Here

    try {
      view.put("name", this.name);
      view.put("owner", this.owner);
      view.put("permissionType", this.permissionType);
      view.put("description", this.description);
      JSONArray ja = new JSONArray();
      for(int i=0;i<this.pages.length;i++) {
        ja.add(this.pages[i].deserialize());
      }
      view.put("pages", (JSONArray) ja);
    } catch (Exception e){
      log.error(ExceptionUtil.getStackTrace(e));
    }
View Full Code Here

  public void testUserSave() {
    try {
    UserBean user = new UserBean();
    user.setId("admin");
    user.setProperty("testKey", "testValue");
    JSONArray ja = new JSONArray();
    user.setViews(ja);
    client = Client.create();
    resource = client.resource("http://localhost:"+restPort);
    ReturnCodeBean result = resource.path("/hicc/v1/user").
    header("Content-Type","application/json").
View Full Code Here

      }
      try {
        int size = ((JSONArray) json.get("parameters")).size();
        ParametersBean[] list = new ParametersBean[size];
        for(int i=0;i<size;i++) {
          JSONArray jsonArray = (JSONArray) json.get("parameters");
          list[i] = new ParametersBean((JSONObject) jsonArray.get(i));
        }
        this.parameters=list;
      } catch (Exception e) {
        this.parameters=null;
      }
View Full Code Here

      json.put("description", this.description);
      json.put("version", this.version);
      json.put("categories", this.categories);
      json.put("refresh", this.refresh);
      json.put("url", this.url);
      JSONArray ja = new JSONArray();
      if(this.parameters!=null) {
        for(int i=0;i<this.parameters.length;i++) {
          ja.add(this.parameters[i].deserialize());
        }
      }
      json.put("parameters", (JSONArray) ja);
    } catch (Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
View Full Code Here

TOP

Related Classes of org.json.simple.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.