package simulator.factories; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import simulator.exceptions.ContClassException; import simulator.misc.Pair; import simulator.model.Event; import simulator.model.NewSetContClassEvent; public class SetContClassEventBuilder extends Builder { public SetContClassEventBuilder() { super("set_cont_class"); // TODO Auto-generated constructor stub } @Override protected Event createTheInstance(JSONObject data) { try { return new NewSetContClassEvent(data.getInt("time"), this.createArray(data.getJSONArray("info"))); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (ContClassException e) { // TODO Auto-generated catch block e.getMessage(); return null; } } private List> createArray(JSONArray infoArray){ List> info = new ArrayList>(); for (int i = 0; i < infoArray.length(); i++) { info.add(i, new Pair(infoArray.getJSONObject(i).getString("vehicle"), infoArray.getJSONObject(i).getInt("class"))); } return info; } }