src/com/company/Server/ReadWriteFiles.java
public void addInfectedCounty(String county) {

        File file = new File("src/com/company/Data/Users.json");

        if (file.exists()) {
            // Caso que o ficheiro exista
            try {
                JSONParser jsonParser = new JSONParser();
                JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));

                JSONArray listCounties = (JSONArray) obj.get("Counties");

                JSONObject countyObj;
                boolean found = false;

                for (int i = 0; !found && i < listCounties.size(); i++) {
                    countyObj = (JSONObject) listCounties.get(i);

                    if (countyObj.get("name").equals(county)) {
                        found = true;
                        int totalAdd = Integer.parseInt(countyObj.get("infectedTot").toString()) + 1;

                        ((JSONObject) listCounties.get(i)).put("infectedTot", totalAdd);
                    }

                }

                JSONArray unregisteredUsers = (JSONArray) obj.get("UnregisteredUsers");
                JSONArray register = (JSONArray) obj.get("Registry");

                JSONObject objWrite = new JSONObject();

                objWrite.put("UnregisteredUsers", unregisteredUsers);
                objWrite.put("Registry", register);
                objWrite.put("Counties", listCounties);

                FileWriter fileWriter = new FileWriter(file.getPath());

                fileWriter.write(objWrite.toJSONString());

                fileWriter.close();

            } catch (ParseException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
/**
     * Method responsible for adding a person to the total number of infected in a given county
     *
     * @param county county's name
     */
Method responsible for adding a person to the total number of infected in a given county
@param county county's name
Method responsible for adding a person to the total number of infected in a given county @param county county ' s name
public void addInfectedCounty(String county) {
        File file = new File("src/com/company/Data/Users.json");
        if (file.exists()) {
            try {
                JSONParser jsonParser = new JSONParser();
                JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));
                JSONArray listCounties = (JSONArray) obj.get("Counties");
                JSONObject countyObj;
                boolean found = false;
                for (int i = 0; !found && i < listCounties.size(); i++) {
                    countyObj = (JSONObject) listCounties.get(i);
                    if (countyObj.get("name").equals(county)) {
                        found = true;
                        int totalAdd = Integer.parseInt(countyObj.get("infectedTot").toString()) + 1;
                        ((JSONObject) listCounties.get(i)).put("infectedTot", totalAdd);
                    }
                }
                JSONArray unregisteredUsers = (JSONArray) obj.get("UnregisteredUsers");
                JSONArray register = (JSONArray) obj.get("Registry");
                JSONObject objWrite = new JSONObject();
                objWrite.put("UnregisteredUsers", unregisteredUsers);
                objWrite.put("Registry", register);
                objWrite.put("Counties", listCounties);
                FileWriter fileWriter = new FileWriter(file.getPath());
                fileWriter.write(objWrite.toJSONString());
                fileWriter.close();
            } catch (ParseException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
public void addInfectedCounty ( String county ) { File file = new File ( "src/com/company/Data/Users.json" ) ; if ( file . exists ( ) ) { try { JSONParser jsonParser = new JSONParser ( ) ; JSONObject obj = ( JSONObject ) jsonParser . parse ( new FileReader ( file . getPath ( ) ) ) ; JSONArray listCounties = ( JSONArray ) obj . get ( "Counties" ) ; JSONObject countyObj ; boolean found = false ; for ( int i = 0 ; ! found && i < listCounties . size ( ) ; i ++ ) { countyObj = ( JSONObject ) listCounties . get ( i ) ; if ( countyObj . get ( "name" ) . equals ( county ) ) { found = true ; int totalAdd = Integer . parseInt ( countyObj . get ( "infectedTot" ) . toString ( ) ) + 1 ; ( ( JSONObject ) listCounties . get ( i ) ) . put ( "infectedTot" , totalAdd ) ; } } JSONArray unregisteredUsers = ( JSONArray ) obj . get ( "UnregisteredUsers" ) ; JSONArray register = ( JSONArray ) obj . get ( "Registry" ) ; JSONObject objWrite = new JSONObject ( ) ; objWrite . put ( "UnregisteredUsers" , unregisteredUsers ) ; objWrite . put ( "Registry" , register ) ; objWrite . put ( "Counties" , listCounties ) ; FileWriter fileWriter = new FileWriter ( file . getPath ( ) ) ; fileWriter . write ( objWrite . toJSONString ( ) ) ; fileWriter . close ( ) ; } catch ( ParseException e ) { e . printStackTrace ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }
Method responsible for adding a person to the total number of infected in a given county
 @param county county's name
Method responsible for adding a person to the total number of infected in a given county @param county county ' s name
// Caso que o ficheiro exista