use of com.google.firestore.v1.DocumentTransform.FieldTransform in project firebase-android-sdk by firebase.
the class Mutation method serverTransformResults.
/**
* Creates a list of "transform results" (a transform result is a field value representing the
* result of applying a transform) for use after a mutation containing transforms has been
* acknowledged by the server.
*
* @param mutableDocument The current state of the document after applying all previous mutations.
* @param serverTransformResults The transform results received by the server.
* @return A map of fields to transform results.
*/
protected Map<FieldPath, Value> serverTransformResults(MutableDocument mutableDocument, List<Value> serverTransformResults) {
Map<FieldPath, Value> transformResults = new HashMap<>(fieldTransforms.size());
hardAssert(fieldTransforms.size() == serverTransformResults.size(), "server transform count (%d) should match field transform count (%d)", serverTransformResults.size(), fieldTransforms.size());
for (int i = 0; i < serverTransformResults.size(); i++) {
FieldTransform fieldTransform = fieldTransforms.get(i);
TransformOperation transform = fieldTransform.getOperation();
Value previousValue = mutableDocument.getField(fieldTransform.getFieldPath());
transformResults.put(fieldTransform.getFieldPath(), transform.applyToRemoteDocument(previousValue, serverTransformResults.get(i)));
}
return transformResults;
}
Aggregations