Search in sources :

Example 6 with FieldTransform

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;
}
Also used : HashMap(java.util.HashMap) FieldPath(com.google.firebase.firestore.model.FieldPath) ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value)

Aggregations

ObjectValue (com.google.firebase.firestore.model.ObjectValue)3 Value (com.google.firestore.v1.Value)3 ArrayList (java.util.ArrayList)3 FieldPath (com.google.firebase.firestore.model.FieldPath)2 FieldTransform (com.google.firestore.v1.DocumentTransform.FieldTransform)2 HashMap (java.util.HashMap)2 Timestamp (com.google.firebase.Timestamp)1 DeleteMutation (com.google.firebase.firestore.model.mutation.DeleteMutation)1 FieldTransform (com.google.firebase.firestore.model.mutation.FieldTransform)1 Mutation (com.google.firebase.firestore.model.mutation.Mutation)1 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)1 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)1 Precondition (com.google.firebase.firestore.model.mutation.Precondition)1 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)1 VerifyMutation (com.google.firebase.firestore.model.mutation.VerifyMutation)1 DocumentTransform (com.google.firestore.v1.DocumentTransform)1 Write (com.google.firestore.v1.Write)1 Builder (com.google.firestore.v1.Write.Builder)1 ByteString (com.google.protobuf.ByteString)1