src/com/company/Server/ReadWriteFiles.java
public void writeUnregisteredUsers(int id) {
        try {
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));

            JSONArray unregisteredUser = (JSONArray) obj.get("UnregisteredUsers");

            boolean isExist = false;
            JSONObject idUnregistered;

            for (int i = 0; !isExist && i < unregisteredUser.size(); i++) {
                idUnregistered = (JSONObject) unregisteredUser.get(i);

                if (Integer.parseInt(idUnregistered.get("id").toString()) == id) {
                    isExist = true;
                }
            }

            if (!isExist) {
                JSONObject unregisteredUsers = new JSONObject();

                unregisteredUsers.put("id", id);

                unregisteredUser.add(unregisteredUsers);

                JSONArray county = (JSONArray) obj.get("Counties");
                JSONArray register = (JSONArray) obj.get("Registry");

                JSONObject objWrite = new JSONObject();

                objWrite.put("UnregisteredUsers", unregisteredUser);
                objWrite.put("Registry", register);
                objWrite.put("Counties", county);

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

                fileWriter.write(objWrite.toJSONString());

                fileWriter.close();
            }

        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
/**
     * Method responsible for writing to a JSON file users who have been added to nearby contacts and who are not yet
     * registered in the application
     *
     * @param id unregistered client id
     */
Method responsible for writing to a JSON file users who have been added to nearby contacts and who are not yet
registered in the application

@param id unregistered client id
Method responsible for writing to a JSON file users who have been added to nearby contacts and who are not yet registered in the application @param id unregistered client id
public void writeUnregisteredUsers(int id) {
        try {
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));
            JSONArray unregisteredUser = (JSONArray) obj.get("UnregisteredUsers");
            boolean isExist = false;
            JSONObject idUnregistered;
            for (int i = 0; !isExist && i < unregisteredUser.size(); i++) {
                idUnregistered = (JSONObject) unregisteredUser.get(i);
                if (Integer.parseInt(idUnregistered.get("id").toString()) == id) {
                    isExist = true;
                }
            }
            if (!isExist) {
                JSONObject unregisteredUsers = new JSONObject();
                unregisteredUsers.put("id", id);
                unregisteredUser.add(unregisteredUsers);
                JSONArray county = (JSONArray) obj.get("Counties");
                JSONArray register = (JSONArray) obj.get("Registry");
                JSONObject objWrite = new JSONObject();
                objWrite.put("UnregisteredUsers", unregisteredUser);
                objWrite.put("Registry", register);
                objWrite.put("Counties", county);
                FileWriter fileWriter = new FileWriter(file.getPath());
                fileWriter.write(objWrite.toJSONString());
                fileWriter.close();
            }
        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
public void writeUnregisteredUsers ( int id ) { try { JSONObject obj = ( JSONObject ) jsonParser . parse ( new FileReader ( file . getPath ( ) ) ) ; JSONArray unregisteredUser = ( JSONArray ) obj . get ( "UnregisteredUsers" ) ; boolean isExist = false ; JSONObject idUnregistered ; for ( int i = 0 ; ! isExist && i < unregisteredUser . size ( ) ; i ++ ) { idUnregistered = ( JSONObject ) unregisteredUser . get ( i ) ; if ( Integer . parseInt ( idUnregistered . get ( "id" ) . toString ( ) ) == id ) { isExist = true ; } } if ( ! isExist ) { JSONObject unregisteredUsers = new JSONObject ( ) ; unregisteredUsers . put ( "id" , id ) ; unregisteredUser . add ( unregisteredUsers ) ; JSONArray county = ( JSONArray ) obj . get ( "Counties" ) ; JSONArray register = ( JSONArray ) obj . get ( "Registry" ) ; JSONObject objWrite = new JSONObject ( ) ; objWrite . put ( "UnregisteredUsers" , unregisteredUser ) ; objWrite . put ( "Registry" , register ) ; objWrite . put ( "Counties" , county ) ; FileWriter fileWriter = new FileWriter ( file . getPath ( ) ) ; fileWriter . write ( objWrite . toJSONString ( ) ) ; fileWriter . close ( ) ; } } catch ( IOException | ParseException e ) { e . printStackTrace ( ) ; } }
Method responsible for writing to a JSON file users who have been added to nearby contacts and who are not yet
 registered in the application
Method responsible for writing to a JSON file users who have been added to nearby contacts and who are not yet registered in the application