CONTROLLER.TProcessamentoRodada.java Source code

Java tutorial

Introduction

Here is the source code for CONTROLLER.TProcessamentoRodada.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTROLLER;

import MODEL.Categoria;
import MODEL.Rodada;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

/**
 *
 * @author dinho
 */
public class TProcessamentoRodada implements Runnable {
    private ArrayList<Rodada> rodadas = new ArrayList<>();
    private JSONArray jsonArray;

    public TProcessamentoRodada(JSONArray jsonArray) {
        this.jsonArray = jsonArray;
    }

    public ArrayList<Rodada> getRun() {
        return rodadas;
    }

    @Override
    public void run() {
        ArrayList<String> auxRodada = new ArrayList<>();
        Iterator iteratorRodada = jsonArray.iterator();

        while (iteratorRodada.hasNext()) {
            JSONObject objetoRodada = (JSONObject) iteratorRodada.next();
            String rodada = (String) objetoRodada.get("round");
            auxRodada.add(rodada);
        }

        Set<String> setRodada = new HashSet<>();
        for (String a : auxRodada) {
            setRodada.add(a);
        }
        Iterator<String> iRodada = setRodada.iterator();

        int idRodada = 0;
        while (iRodada.hasNext()) {
            Rodada auxRodadas = new Rodada();
            auxRodadas.setId(idRodada);
            auxRodadas.setRodada(iRodada.next());
            rodadas.add(auxRodadas);
            idRodada++;
        }

    }

}