code: private Map<FieldPath, Object> applyFieldMask(
        Map<String, Object> fields, List<FieldPath> fieldMask) {
      List<FieldPath> remainingFields = new ArrayList<>(fieldMask);
      Map<FieldPath, Object> filteredData =
          applyFieldMask(fields, remainingFields, FieldPath.empty());
  
      if (!remainingFields.isEmpty()) {
        throw new IllegalArgumentException(
            String.format(
                "Field masks contains invalid path. No data exist at field '%s'.",
                remainingFields.get(0)));
      }
  
      return filteredData;
    }
docs: Removes all values in 'fields' that are not specified in 'fieldMask'.