コード例 #1
0
 public void persistIncidents() {
   JSONArray jsonIncidents = new JSONArray();
   for (Incident incident : incidents) {
     jsonIncidents.add(incident.jsonify());
   }
   json.put("incidents", jsonIncidents);
 }
コード例 #2
0
 private void restoreIncidents() {
   JSONArray jsonIncidents = (JSONArray) json.get("incidents");
   for (Object incidentObject : jsonIncidents) {
     JSONObject jsonIncident = (JSONObject) incidentObject;
     String locationID = jsonIncident.get("location").toString();
     Location location = null;
     if (!locationID.isEmpty()) {
       location = getLocation(Integer.parseInt(locationID));
     }
     String dispatcherID = jsonIncident.get("dispatcher").toString();
     Dispatcher dispatcher = null;
     if (!dispatcherID.isEmpty()) {
       dispatcher = getDispatcher(Integer.parseInt(dispatcherID));
     }
     String reporterID = jsonIncident.get("reporter").toString();
     Reporter reporter = null;
     if (!reporterID.isEmpty()) {
       reporter = getReporter(Integer.parseInt(reporterID));
     }
     String typeID = jsonIncident.get("type").toString();
     IncidentType type = null;
     if (!typeID.isEmpty()) {
       type = getIncidentType(Integer.parseInt(typeID));
     }
     incidents.add(Incident.createFromJSON(jsonIncident, type, location, reporter, dispatcher));
   }
 }