public ArrayList<Model_Kantor> view() throws ParseException { ArrayList<Model_Kantor> kantor = new ArrayList<Model_Kantor>(); JSONParser parser = new JSONParser(); Object obj = parser.parse(ioFile.readFile()); JSONObject object = (JSONObject) obj; JSONArray arr = (JSONArray) object.get("data"); for (int i = 0; i < arr.size(); i++) { JSONObject object2 = (JSONObject) arr.get(i); Model_Kantor temp = new Model_Kantor(); temp.setId(object2.get("id").toString()); temp.setNama(object2.get("nama").toString()); temp.setRegional(object2.get("regional").toString()); temp.setArea(object2.get("area").toString()); temp.setAlamat(object2.get("alamat").toString()); temp.setFax(object2.get("fax").toString()); temp.setTelepon(object2.get("telepon").toString()); temp.setLat(object2.get("lat").toString()); temp.setLng(object2.get("lng").toString()); temp.setTeknisi(object2.get("teknisi").toString()); kantor.add(temp); } return kantor; }
public void insert(Model_Kantor kantor) throws ParseException { ArrayList<Model_Kantor> temp = view(); temp.add(kantor); ioFile.writeFile(convert(temp)); }
public void update(Model_Kantor kantor) throws ParseException { ArrayList<Model_Kantor> temp = view(); temp.set(getIndex(kantor.getId()), kantor); ioFile.writeFile(convert(temp)); }
public void init(ArrayList<Model_Kantor> kantor) throws ParseException { ioFile.writeFile(convert(kantor)); }
public void delete(String id) throws ParseException { ArrayList<Model_Kantor> temp = view(); temp.remove(getIndex(id)); ioFile.writeFile(convert(temp)); }