public void persistLocations() { JSONArray jsonLocations = new JSONArray(); for (Location location : locations) { jsonLocations.add(location.jsonify()); } json.put("locations", jsonLocations); }
public Location getLocation(int id) { for (Location location : locations) { if (location.getId() == id) { return location; } } return null; }
private void restoreLocations() { JSONArray jsonLocations = (JSONArray) json.get("locations"); int size = jsonLocations.size(); for (int i = 0; i < size; ++i) { JSONObject jsonLocation = (JSONObject) jsonLocations.get(i); Location location = Location.createFromJSON(jsonLocation); locations.add(location); } }