private Map < FieldPath , Object > applyFieldMask ( Map < String , Object > fields , List < FieldPath > fieldMask , FieldPath root ) { Map < FieldPath , Object > filteredMap = new HashMap <> ( ) ; for ( Entry < String , Object > entry : fields . entrySet ( ) ) { FieldPath currentField = root . append ( FieldPath . of ( entry . getKey ( ) ) ) ; if ( fieldMask . remove ( currentField ) ) { filteredMap . put ( currentField , entry . getValue ( ) ) ; } else if ( entry . getValue ( ) instanceof Map ) { filteredMap . putAll ( applyFieldMask ( ( Map < String , Object > ) entry . getValue ( ) , fieldMask , currentField ) ) ; } else if ( entry . getValue ( ) == FieldValue . DELETE_SENTINEL ) { throw new IllegalArgumentException ( String . format ( "Cannot specify FieldValue.delete() for non-merged field '%s'." , currentField ) ) ; } } return filteredMap ; }
Strips all values in fields that are not specified in fieldMask . Modifies fieldMask inline and removes all matched fields .