/**
   * Deletes an Address object from the application's SQLite database<br>
   * <br>
   * <b>NOTE:</b> This method uses the given Address's ID field to determine which record in the
   * database to delete
   *
   * @param a - The Address object to be deleted
   */
  public void deleteAddress(Address a) {
    long id = a.getId();

    // Query the database via the ContentProvider and delete the record with the matching ID
    int recordsDeleted =
        mContentResolver.delete(
            DatabaseContentProvider.CONTENT_URI_ADDRESSES,
            AddressesTable.COLUMN_ID + " = ? ",
            new String[] {String.valueOf(id)});
    if (recordsDeleted > 0) {
      Log.i(TAG, "Address " + a.getAddress() + " deleted from database");
    } else {
      Log.e(
          TAG,
          "Unable to find the address specified for deletion. The address specified was "
              + a.getAddress());
    }
  }
  /**
   * Takes an Address object and adds it to the app's SQLite database as a new record, returning the
   * ID of the newly created record.
   *
   * @param a - The Address object to be added
   * @return id - A long value representing the ID of the newly created record
   */
  public long addAddress(Address a) {
    ContentValues values = new ContentValues();
    values.put(AddressesTable.COLUMN_CORRESPONDING_PUBKEY_ID, a.getCorrespondingPubkeyId());
    values.put(AddressesTable.COLUMN_LABEL, a.getLabel());
    values.put(AddressesTable.COLUMN_ADDRESS, a.getAddress());
    values.put(AddressesTable.COLUMN_PRIVATE_SIGNING_KEY, a.getPrivateSigningKey());
    values.put(AddressesTable.COLUMN_PRIVATE_ENCRYPTION_KEY, a.getPrivateEncryptionKey());
    values.put(
        AddressesTable.COLUMN_RIPE_HASH, Base64.encodeToString(a.getRipeHash(), Base64.DEFAULT));
    values.put(AddressesTable.COLUMN_TAG, Base64.encodeToString(a.getTag(), Base64.DEFAULT));

    Uri insertionUri =
        mContentResolver.insert(DatabaseContentProvider.CONTENT_URI_ADDRESSES, values);
    Log.i(TAG, "Address with address " + a.getAddress() + " saved to database");

    // Parse the ID of the newly created record from the insertion Uri
    String uriString = insertionUri.toString();
    String idString = uriString.substring(uriString.indexOf("/") + 1);
    long id = Long.parseLong(idString);
    return id;
  }
  /**
   * Updates the database record for a given Address object<br>
   * <br>
   * <b>NOTE:</b> This method uses the given Address's ID field to determine which record in the
   * database to update
   *
   * @param a - The Address object to be updated
   */
  public void updateAddress(Address a) {
    ContentValues values = new ContentValues();
    values.put(AddressesTable.COLUMN_CORRESPONDING_PUBKEY_ID, a.getCorrespondingPubkeyId());
    values.put(AddressesTable.COLUMN_LABEL, a.getLabel());
    values.put(AddressesTable.COLUMN_ADDRESS, a.getAddress());
    values.put(AddressesTable.COLUMN_PRIVATE_SIGNING_KEY, a.getPrivateSigningKey());
    values.put(AddressesTable.COLUMN_PRIVATE_ENCRYPTION_KEY, a.getPrivateEncryptionKey());
    values.put(
        AddressesTable.COLUMN_RIPE_HASH, Base64.encodeToString(a.getRipeHash(), Base64.DEFAULT));
    values.put(AddressesTable.COLUMN_TAG, Base64.encodeToString(a.getTag(), Base64.DEFAULT));

    long id = a.getId();

    // Query the database via the ContentProvider and update the record with the matching ID
    mContentResolver.update(
        DatabaseContentProvider.CONTENT_URI_ADDRESSES,
        values,
        AddressesTable.COLUMN_ID + " = ? ",
        new String[] {String.valueOf(id)});

    Log.i(TAG, "Address ID " + id + " updated");
  }