Example usage for org.json.simple JSONArray get

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

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.apifest.doclet.integration.tests.DocletTest.java

@Test
public void check_what_doclet_will_generate_correct_metrics_result_parameters() throws Exception {
    // GIVEN/*from  www. jav  a2 s.  c om*/
    String parserFilePath = "./all-mappings-docs.json";
    Map<String, ResultParamDocumentation> resNameToTypeMap = new HashMap<String, ResultParamDocumentation>();
    addResultParamToMap("channel", "string", "The **channel** description", true, resNameToTypeMap);
    addResultParamToMap("updated_time", "string", "The **updated_time** description", true, resNameToTypeMap);
    addResultParamToMap("request_handle", "string", "The **request_handle** description", true,
            resNameToTypeMap);
    addResultParamToMap("sentiment.score", "string", "The **sentiment_score** description", true,
            resNameToTypeMap);
    addResultParamToMap("sentiment.positive", "string", "The **sentiment_positive** description", true,
            resNameToTypeMap);
    addResultParamToMap("sentiment.neutral", "string", "The **sentiment_neutral** description", true,
            resNameToTypeMap);
    addResultParamToMap("sentiment.negative", "string", "The **sentiment_negative** description", true,
            resNameToTypeMap);
    addResultParamToMap("engagement.replies", "integer", "The **engagement_replies** description", true,
            resNameToTypeMap);
    addResultParamToMap("engagement.tweets", "integer", "The **engagement_tweets** description", true,
            resNameToTypeMap);
    // WHEN
    runDoclet();
    // THEN
    JSONParser parser = new JSONParser();
    FileReader fileReader = null;
    try {
        fileReader = new FileReader(parserFilePath);
        JSONObject json = (JSONObject) parser.parse(fileReader);
        JSONArray arr = (JSONArray) json.get("endpoints");
        JSONObject obj = (JSONObject) arr.get(1);

        JSONArray resParam = (JSONArray) obj.get("resultParams");
        for (int i = 0; i < resParam.size(); i++) {
            JSONObject currentParam = (JSONObject) resParam.get(i);
            String currentName = (String) currentParam.get("name");
            ResultParamDocumentation correctCurrentParam = resNameToTypeMap.get(currentName);
            Assert.assertEquals((String) currentParam.get("type"), correctCurrentParam.getType());
            Assert.assertEquals((String) currentParam.get("name"), correctCurrentParam.getName());
            Assert.assertEquals((String) currentParam.get("description"), correctCurrentParam.getDescription());
            Assert.assertEquals(currentParam.get("required"), correctCurrentParam.isRequired());

        }
    } finally {
        if (fileReader != null) {
            fileReader.close();
        }
        deleteJsonFile(parserFilePath);
    }
}

From source file:net.duckling.ddl.web.controller.JoinPublicTeamController.java

/**
 * ??/*from  w ww. j  a v a2  s  .c  o  m*/
 * @param all ?
 * @param my ?
 * @param myApplicant ?
 * @return
 */
private JSONArray checkStatus(List<Team> all, List<Team> my, List<TeamApplicant> myApplicant) {
    if (isEmpty(all)) {
        return null;
    }
    int size = all.size();
    JSONArray status = initStatusMap(size);
    if (isEmpty(my) && isEmpty(myApplicant)) {
        return status;
    }
    for (int i = 0; i < size; i++) {
        int tid = all.get(i).getId();
        JSONObject obj = (JSONObject) status.get(i);
        boolean isTeamMember = amITeamMemberOfThisTeam(my, tid);
        obj.put("status", (isTeamMember) ? TEAM_MEMBER : OUTSIDE);
        if (!isTeamMember) {
            updateStatusIfIApplied(myApplicant, tid, obj);
        }
    }
    return status;
}

From source file:net.phyloviz.goeburst.GoeBurstItemFactory.java

private Map<Integer, GOeBurstNodeExtended> getNodes(Map<String, GOeBurstNodeExtended> td, JSONArray onodes) {

    Map<Integer, GOeBurstNodeExtended> nodes = new HashMap<>();
    for (Iterator<JSONObject> nIt = onodes.iterator(); nIt.hasNext();) {
        JSONObject node = nIt.next();/*from  w w w.j  av  a 2 s  .c  o m*/
        Integer uid = (int) (long) node.get("id");
        String profile = (String) node.get("profile");
        JSONArray group_lvs = (JSONArray) node.get("group-lvs");
        JSONArray graph_lvs = (JSONArray) node.get("graph-lvs");
        JSONArray slvs = (JSONArray) node.get("slvs");
        JSONArray dlvs = (JSONArray) node.get("dlvs");

        GOeBurstNodeExtended n = td.get(profile);
        n.setLV(SLV, (int) (long) group_lvs.get(SLV));
        n.setLV(DLV, (int) (long) group_lvs.get(DLV));
        n.setLV(TLV, (int) (long) group_lvs.get(TLV));
        n.setLV(SAT, (int) (long) group_lvs.get(SAT));
        goeburstStats.setSTlvs(n, (int) (long) graph_lvs.get(SLV), (int) (long) graph_lvs.get(DLV),
                (int) (long) graph_lvs.get(TLV), (int) (long) graph_lvs.get(SAT));
        for (Iterator profileIt = slvs.iterator(); profileIt.hasNext();) {
            String p = (String) profileIt.next();
            GOeBurstNodeExtended pNode = td.get(p);
            n.addSLV(pNode);
        }
        for (Iterator profileIt = dlvs.iterator(); profileIt.hasNext();) {
            String p = (String) profileIt.next();
            GOeBurstNodeExtended pNode = td.get(p);
            n.addDLV(pNode);
        }
        nodes.put(uid, n);

    }
    return nodes;
}

From source file:functionaltests.RestSchedulerTagTest.java

@Test
public void testTaskResultByTag() throws Exception {
    HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/LOOP-T2-1/result");
    JSONArray jsonArray = toJsonArray(response);

    System.out.println(jsonArray.toJSONString());

    ArrayList<String> taskNames = new ArrayList<>(4);
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject id = (JSONObject) ((JSONObject) jsonArray.get(i)).get("id");
        String name = (String) id.get("readableName");
        taskNames.add(name);//from   w ww.ja v  a 2s  .c o  m
    }

    assertTrue(taskNames.contains("T1#1"));
    assertTrue(taskNames.contains("Print1#1"));
    assertTrue(taskNames.contains("Print2#1"));
    assertTrue(taskNames.contains("T2#1"));
    assertEquals(4, jsonArray.size());
}

From source file:org.opencastproject.userdirectory.jpa.JpaUserAndRoleProvider.java

/**
 * Parses a User from a json representation.
 * // w  ww. j a  va2  s.  c o  m
 * @param json
 *          the user as json
 * @return the user
 * @throws IOException
 *           if the json can not be parsed
 */
protected User fromJson(String json) throws IOException {
    JSONObject jsonObject;
    try {
        jsonObject = (JSONObject) new JSONParser().parse(json);
    } catch (ParseException e) {
        throw new IOException(e);
    }
    String username = (String) jsonObject.get(USERNAME);
    String org = securityService.getOrganization().getId();
    JSONArray roleArray = (JSONArray) jsonObject.get(ROLES);
    String[] roles = new String[roleArray.size()];
    for (int i = 0; i < roleArray.size(); i++) {
        roles[i] = (String) roleArray.get(i);
    }
    return new User(username, org, roles);
}

From source file:de.fhg.fokus.odp.portal.datasets.searchresults.BrowseDataSetsSearchResults.java

/**
 * This method adds for each package in our {@link JSONArray} the correct
 * number of comments and ratings in a specific array. These arrays will be
 * saved our {@link RenderRequest};//from  w w w .  ja va  2  s  .c o  m
 * 
 * @param request
 *            the {@link RenderRequest}
 * @param arr
 *            the {@link JSONArray}
 */
private void addNumberOfRatingsAndCommentsToRequest(RenderRequest request, JSONArray arr) {
    int[] ratingsNumberArray = new int[arr.size()];
    int[] commentsNumberArray = new int[arr.size()];
    for (int i = 0; i < arr.size(); i++) {
        JSONObject dataset = (JSONObject) arr.get(i);
        JSONObject extras = (JSONObject) dataset.get("extras");
        // don't have any extras -> dont have ratings and comments
        if (extras == null) {
            ratingsNumberArray[i] = 0;
            commentsNumberArray[i] = 0;
        } else {
            String rating = (String) extras.get("ratings");
            String comments = (String) extras.get(BrowseDataSetsSearchResults.COMMENTS_STRING);
            // don't have any ratings -> ratings = 0
            if (rating == null) {
                ratingsNumberArray[i] = 0;
            } else {
                int ratingsNumber = countNumberofOccurences(rating, '{');
                ratingsNumberArray[i] = ratingsNumber;
            }
            // don't have any comments -> ratings = 0
            if (comments == null) {
                commentsNumberArray[i] = 0;
            } else {
                int commentsNumber = countNumberofOccurences(comments, '{');
                commentsNumberArray[i] = commentsNumber;
            }
        }
    }

    request.setAttribute("ratingsNumber", ratingsNumberArray);
    request.setAttribute("commentsNumber", commentsNumberArray);
}

From source file:de.ingrid.iplug.dsc.utils.BwstrLocUtil.java

/**
 * Get the center coordinate from the parsed response.
 * //from   w  w  w .ja  v  a2s .  c om
 * @param parsedResponse
 * @return The center in Double[centerLon, centerLat].
 */
public Double[] getCenter(JSONObject parsedResponse) {

    Double[] result = null;

    try {
        JSONObject re = (JSONObject) ((JSONArray) parsedResponse.get("result")).get(0);
        JSONArray coordinates = (JSONArray) ((JSONObject) re.get("geometry")).get("coordinates");
        int maxNoOfCoordinates = 0;
        Double centerLon = null;
        Double centerLat = null;
        for (int i = 0; i < coordinates.size(); i++) {
            JSONArray a = (JSONArray) coordinates.get(i);
            maxNoOfCoordinates += a.size();
        }
        int cnt = 0;
        int centerCnt = ((int) (maxNoOfCoordinates / 2));

        for (Object c : coordinates) {
            JSONArray a = (JSONArray) c;
            for (Object cc : a) {
                cnt++;
                JSONArray aa = (JSONArray) cc;
                double lon = (Double) aa.get(0);
                double lat = (Double) aa.get(1);
                if (cnt == centerCnt) {
                    centerLon = lon;
                    centerLat = lat;
                    break;
                }
            }
        }

        result = new Double[] { centerLon, centerLat };
    } catch (Exception e) {
        log.error("Error parsing BwstrLoc response: " + parsedResponse.toJSONString(), e);
    }

    return result;
}

From source file:co.mcme.animations.animations.MCMEAnimation.java

private void loadTriggers() {
    JSONArray interactions = (JSONArray) animationConfiguration.get("interactions");

    for (int i = 0; i < interactions.size(); i++) {
        JSONObject interaction = (JSONObject) interactions.get(i);
        JSONObject interactionType = (JSONObject) interaction.get("block_interaction");

        if (null != interactionType) {
            //BLOCK INTERACTION
            int frame = ((Long) interactionType.get("frame")).intValue();
            JSONArray blocks = (JSONArray) interactionType.get("blocks");
            ArrayList<Vector> blocksArray = new ArrayList<Vector>();
            for (int j = 0; j < blocks.size(); j++) {
                JSONObject coordsObj = (JSONObject) blocks.get(j);
                JSONArray coords = (JSONArray) coordsObj.get("block");
                Vector v = new Vector(((Long) coords.get(0)).intValue(), ((Long) coords.get(1)).intValue(),
                        ((Long) coords.get(2)).intValue());
                blocksArray.add(v);/*from  w  w w  .j  a  v  a 2s . c  om*/
            }
            if (blocksArray.size() > 0) {
                BlockInteractTrigger bit = new BlockInteractTrigger(this, blocksArray, frame);
                MCMEAnimations.triggers.add(bit);
            }
            continue;
        }

        interactionType = (JSONObject) interaction.get("shape_interaction");

        if (null != interactionType) {
            //SHAPE INTERACTION
            int frame = ((Long) interactionType.get("frame")).intValue();
            ShapeInteractTrigger sit = new ShapeInteractTrigger(this, frame);
            MCMEAnimations.triggers.add(sit);
            continue;
        }

        interactionType = (JSONObject) interaction.get("player_chat");

        if (null != interactionType) {
            //PLAYER CHAT
            int frame = ((Long) interactionType.get("frame")).intValue();
            double distance = ((Double) interactionType.get("distance"));
            String message = (String) interactionType.get("message");
            PlayerChatTrigger pct = new PlayerChatTrigger(this, frame, distance, message);
            MCMEAnimations.triggers.add(pct);
            continue;
        }

        interactionType = (JSONObject) interaction.get("always_active");

        if (null != interactionType) {
            //ALWAYS ACTIVE
            AlwaysActiveTrigger aat = new AlwaysActiveTrigger(this);
            MCMEAnimations.triggers.add(aat);
            continue;
        }

    }
}

From source file:hoot.services.nativeInterfaces.ProcessStreamInterface.java

/**
 * Creates direct exec call/* ww  w.  j  av a 2s  .c om*/
 * like hoot --ogr2osm target input output if the "exectype" is "hoot"
 *
 * @param cmd
 * @return
 */

private String[] createCmdArray(JSONObject cmd) {
    ArrayList<String> execCmd = new ArrayList<String>();
    try {
        execCmd.add("hoot");
        execCmd.add("--" + (String) cmd.get("exec"));
        JSONArray params = (JSONArray) cmd.get("params");
        int nParams = params.size();
        for (int i = 0; i < nParams; i++) {
            JSONObject param = (JSONObject) params.get(i);
            Iterator iter = param.entrySet().iterator();

            String arg = "";
            while (iter.hasNext()) {
                Map.Entry mEntry = (Map.Entry) iter.next();
                arg = (String) mEntry.getValue();
            }
            execCmd.add(arg);

        }
    } catch (Exception ex) {
        log.error("Failed to parse job params. Reason: " + ex.getMessage());
    }

    Object[] objectArray = execCmd.toArray();
    return Arrays.copyOf(objectArray, objectArray.length, String[].class);
}

From source file:co.mcme.animations.animations.MCMEAnimation.java

private void loadActions() {
    JSONArray actions = (JSONArray) animationConfiguration.get("actions");
    if (null != actions) {
        for (int i = 0; i < actions.size(); i++) {
            JSONObject action = (JSONObject) actions.get(i);

            JSONObject actionType = (JSONObject) action.get("explosion");
            if (null != actionType) {
                int frame = ((Long) actionType.get("frame")).intValue();
                ExplosionAction exp = new ExplosionAction(this, frame);
                MCMEAnimations.actions.add(exp);
            }/*from w w w .  ja v  a  2 s .  c  om*/

            actionType = (JSONObject) action.get("move_players");
            if (null != actionType) {
                int frame = ((Long) actionType.get("frame")).intValue();
                //                    JSONArray direction = (JSONArray) actionType.get("direction");
                //                    if (null != direction) {
                //                        double x = (Double) direction.get(0);
                //                        double y = (Double) direction.get(1);
                //                        double z = (Double) direction.get(2);
                //
                //                        com.sk89q.worldedit.Vector v = new com.sk89q.worldedit.Vector(x, y, z);
                //                        MovePlayersAction mpa = new MovePlayersAction(this, frame, v);
                MovePlayersAction mpa = new MovePlayersAction(this, frame);
                MCMEAnimations.actions.add(mpa);
                //                    }
            }

            actionType = (JSONObject) action.get("chain_animation");
            if (null != actionType) {
                int frame = ((Long) actionType.get("frame")).intValue();
                String target = (String) actionType.get("target");
                ChainAnimationAction caa = new ChainAnimationAction(this, frame, target);
                MCMEAnimations.actions.add(caa);
            }

            actionType = (JSONObject) action.get("sound");
            if (null != actionType) {
                int frame = ((Long) actionType.get("frame")).intValue();
                String sound = (String) actionType.get("sound");
                double radius = (Double) actionType.get("radius");
                PlaySoundAction psa = new PlaySoundAction(this, frame, sound, radius);
                MCMEAnimations.actions.add(psa);
            }
        }
    }
}