use of com.google.firestore.v1.MapValue in project firebase-android-sdk by firebase.
the class Values method objectEquals.
private static boolean objectEquals(Value left, Value right) {
MapValue leftMap = left.getMapValue();
MapValue rightMap = right.getMapValue();
if (leftMap.getFieldsCount() != rightMap.getFieldsCount()) {
return false;
}
for (Map.Entry<String, Value> entry : leftMap.getFieldsMap().entrySet()) {
Value otherEntry = rightMap.getFieldsMap().get(entry.getKey());
if (!equals(entry.getValue(), otherEntry)) {
return false;
}
}
return true;
}
use of com.google.firestore.v1.MapValue in project firebase-android-sdk by firebase.
the class FirestoreIndexValueWriter method writeIndexMap.
private void writeIndexMap(MapValue mapIndexValue, DirectionalIndexByteEncoder encoder) {
writeValueTypeLabel(encoder, INDEX_TYPE_MAP);
for (Map.Entry<String, Value> entry : mapIndexValue.getFieldsMap().entrySet()) {
String key = entry.getKey();
Value value = entry.getValue();
writeIndexString(key, encoder);
writeIndexValueAux(value, encoder);
}
}
use of com.google.firestore.v1.MapValue in project firebase-android-sdk by firebase.
the class ObjectValue method buildProto.
/**
* Returns the Protobuf that backs this ObjectValue.
*
* <p>This method applies any outstanding modifications and memoizes the result. Further
* invocations are based on this memoized result.
*/
private Value buildProto() {
synchronized (overlayMap) {
MapValue mergedResult = applyOverlay(FieldPath.EMPTY_PATH, overlayMap);
if (mergedResult != null) {
partialValue = Value.newBuilder().setMapValue(mergedResult).build();
overlayMap.clear();
}
}
return partialValue;
}
use of com.google.firestore.v1.MapValue in project firebase-android-sdk by firebase.
the class ObjectValue method extractFieldMask.
private FieldMask extractFieldMask(MapValue value) {
Set<FieldPath> fields = new HashSet<>();
for (Map.Entry<String, Value> entry : value.getFieldsMap().entrySet()) {
FieldPath currentPath = FieldPath.fromSingleSegment(entry.getKey());
if (Values.isMapValue(entry.getValue())) {
FieldMask nestedMask = extractFieldMask(entry.getValue().getMapValue());
Set<FieldPath> nestedFields = nestedMask.getMask();
if (nestedFields.isEmpty()) {
// Preserve the empty map by adding it to the FieldMask.
fields.add(currentPath);
} else {
// For nested and non-empty ObjectValues, add the FieldPath of the leaf nodes.
for (FieldPath nestedPath : nestedFields) {
fields.add(currentPath.append(nestedPath));
}
}
} else {
fields.add(currentPath);
}
}
return FieldMask.fromSet(fields);
}
use of com.google.firestore.v1.MapValue in project firebase-android-sdk by firebase.
the class ObjectValue method applyOverlay.
/**
* Applies any overlays from {@code currentOverlays} that exist at `currentPath` and returns the
* merged data at {@code currentPath} (or {@code null} if there were no changes).
*
* @param currentPath The path at the current nesting level. Can be set to {@code
* FieldValue.EMPTY_PATH} to represent the root.
* @param currentOverlays The overlays at the current nesting level in the same format as {@code
* overlayMap}.
* @return The merged data at `currentPath` or null if no modifications were applied.
*/
@Nullable
private MapValue applyOverlay(FieldPath currentPath, Map<String, Object> currentOverlays) {
boolean modified = false;
@Nullable Value existingValue = extractNestedValue(partialValue, currentPath);
MapValue.Builder resultAtPath = Values.isMapValue(existingValue) ? // of the existing data.
existingValue.getMapValue().toBuilder() : MapValue.newBuilder();
for (Map.Entry<String, Object> entry : currentOverlays.entrySet()) {
String pathSegment = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
@Nullable MapValue nested = applyOverlay(currentPath.append(pathSegment), (Map<String, Object>) value);
if (nested != null) {
resultAtPath.putFields(pathSegment, Value.newBuilder().setMapValue(nested).build());
modified = true;
}
} else if (value instanceof Value) {
resultAtPath.putFields(pathSegment, (Value) value);
modified = true;
} else if (resultAtPath.containsFields(pathSegment)) {
hardAssert(value == null, "Expected entry to be a Map, a Value or null");
resultAtPath.removeFields(pathSegment);
modified = true;
}
}
return modified ? resultAtPath.build() : null;
}
Aggregations