mercredi 22 avril 2015

How to split a list of defect results from an ArrayList

Hello I am having trouble in splitting the information(severity, summary etc) I get for different components(General, Code Quality etc) in mozilla rest api. When I am calling to get information for a certain component. I get all of it in a single list. What I would like to do is separate the bugs and have each of them in an array. How would I do that? Here is my code for now

package bla_bla;

import java.util.ArrayList;
import java.util.*;
import javax.swing.text.html.parser.Element;

    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.json.*;

    import argo.saj.InvalidSyntaxException;

    public class supermonkey {

    private static ArrayList<BugsList> bugsList;    
    private static ArrayList<BugsList> bugbug;  

    public static void main(String args[]) throws IOException {

        bugsList = new ArrayList<BugsList>();
        bugbug = new ArrayList<BugsList>();
        Document doc = Jsoup.connect("").get();
        String rawData = doc.body().text();
    //  System.out.println(title);
        JSONObject obj = new JSONObject(rawData);

    //  System.out.println(obj);


        JSONArray jsonMainArr = new JSONArray(obj.get("bugs").toString());
        for (int i = 0; i < jsonMainArr.length(); i++) {  // **line 2**
             JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
             JSONObject assigned = childJSONObject.getJSONObject("assigned_to_detail");
          //   JSONObject assigned2 = childJSONObject.getJSONObject("assigned_to_detail");

             int id = assigned.getInt("id");
             BugsList bug = new BugsList();
             BugsList bug2 = new BugsList();

             String severity = childJSONObject.getString("severity");
             String resolution = childJSONObject.getString("resolution");
             String summary = childJSONObject.getString("summary");
             String component = childJSONObject.getString("component");

             // String severity = assigned.getString();
    //       System.out.println("sss  "+ assigned);


        getComponent("Code Quality");
    //  getSeverity(524276);
    //  getResolution(524276);
    //  getSummary(524276);
       public static void getSeverity(int id){
           for(int i =0;i<bugsList.size(); i++){
               if(bugsList.get(i).getId() == id){
                   System.out.println("The id exists in the list " + bugsList.get(i).getSeverity());

       public static void getResolution(int id){
           for(int i =0;i<bugsList.size(); i++){
               if(bugsList.get(i).getId() == id){
                   System.out.println("The id exists in the list and The resolution is" + bugsList.get(i).getResolution());

       public static void getSummary(int id){
           for(int i =0;i<bugsList.size(); i++){
               if(bugsList.get(i).getId() == id){
    System.out.println("The comp.. exists in the list and The summary is   " + bugsList.get(i).getSummary());
        // Current used method
       public static ArrayList<BugsList> getComponent(String component){
           for(int i =0;i<bugsList.size(); i++){
                   System.out.println("(Code Quality) component contains summary  " + bugsList.get(i).getSummary() +" /The resolution is " +                 
    bugsList.get(i).getResolution() + "  /Severity is " + bugsList.get(i).getSeverity());
           return bugbug;


Aucun commentaire:

Enregistrer un commentaire