Skip to content

Commit 522db2f

Browse files
Drop remaining primitive FieldValue types
1 parent 637838b commit 522db2f

27 files changed

+134
-360
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentSnapshot.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.google.firebase.Timestamp;
2222
import com.google.firebase.firestore.model.Document;
2323
import com.google.firebase.firestore.model.DocumentKey;
24-
import com.google.firebase.firestore.model.value.FieldValue;
2524
import com.google.firebase.firestore.util.CustomClassMapper;
25+
import com.google.firestore.v1.Value;
2626
import java.util.Date;
2727
import java.util.Map;
2828

@@ -529,11 +529,11 @@ private Object getInternal(
529529
@NonNull ServerTimestampBehavior serverTimestampBehavior,
530530
boolean timestampsInSnapshots) {
531531
if (doc != null) {
532-
FieldValue val = doc.getField(fieldPath);
532+
Value val = doc.getField(fieldPath);
533533
if (val != null) {
534534
UserDataWriter userDataWriter =
535535
new UserDataWriter(firestore, timestampsInSnapshots, serverTimestampBehavior);
536-
return userDataWriter.convertValue(val.getProto());
536+
return userDataWriter.convertValue(val);
537537
}
538538
}
539539
return null;

firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ private Bound boundFromDocumentSnapshot(
750750
if (orderBy.getField().equals(com.google.firebase.firestore.model.FieldPath.KEY_PATH)) {
751751
components.add(ProtoValues.refValue(firestore.getDatabaseId(), document.getKey()));
752752
} else {
753-
Value value = document.getFieldProto(orderBy.getField());
753+
Value value = document.getField(orderBy.getField());
754754
if (ServerTimestampValue.isServerTimestamp(value)) {
755755
throw new IllegalArgumentException(
756756
"Invalid query. You are trying to start or end a query using a document for which "

firebase-firestore/src/main/java/com/google/firebase/firestore/UserDataWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ Map<String, Object> convertObject(Map<String, Value> mapValue) {
9393
private Object convertServerTimestamp(ServerTimestampValue value) {
9494
switch (serverTimestampBehavior) {
9595
case PREVIOUS:
96-
return value.getPreviousValue() == null
97-
? null
98-
: convertValue(value.getPreviousValue().getProto());
96+
return value.getPreviousValue() == null ? null : convertValue(value.getPreviousValue());
9997
case ESTIMATE:
10098
return !timestampsInSnapshots
10199
? value.getLocalWriteTime().toDate()

firebase-firestore/src/main/java/com/google/firebase/firestore/core/ArrayContainsAnyFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ArrayContainsAnyFilter extends FieldFilter {
3030

3131
@Override
3232
public boolean matches(Document doc) {
33-
Value other = doc.getFieldProto(getField());
33+
Value other = doc.getField(getField());
3434
if (!ProtoValues.isArray(other)) {
3535
return false;
3636
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/ArrayContainsFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ArrayContainsFilter extends FieldFilter {
2727

2828
@Override
2929
public boolean matches(Document doc) {
30-
Value other = doc.getFieldProto(getField());
30+
Value other = doc.getField(getField());
3131
return ProtoValues.isArray(other) && ProtoValues.contains(other.getArrayValue(), getValue());
3232
}
3333
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/Bound.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public boolean sortsBeforeDocument(List<OrderBy> orderBy, Document document) {
8686
comparison =
8787
DocumentKey.fromName(component.getReferenceValue()).compareTo(document.getKey());
8888
} else {
89-
Value docValue = document.getFieldProto(orderByComponent.getField());
89+
Value docValue = document.getField(orderByComponent.getField());
9090
hardAssert(
9191
docValue != null, "Field should exist since document matched the orderBy already.");
9292
comparison = ProtoValues.compare(component, docValue);

firebase-firestore/src/main/java/com/google/firebase/firestore/core/FieldFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static FieldFilter create(FieldPath path, Operator operator, Value value)
9595

9696
@Override
9797
public boolean matches(Document doc) {
98-
Value other = doc.getFieldProto(field);
98+
Value other = doc.getField(field);
9999
// Only compare types with matching backend order (such as double and int).
100100
return other != null
101101
&& ProtoValues.typeOrder(other) == ProtoValues.typeOrder(value)

firebase-firestore/src/main/java/com/google/firebase/firestore/core/InFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.google.firebase.firestore.model.Document;
2020
import com.google.firebase.firestore.model.FieldPath;
21-
import com.google.firebase.firestore.model.value.FieldValue;
2221
import com.google.firebase.firestore.model.value.ProtoValues;
2322
import com.google.firestore.v1.Value;
2423

@@ -31,7 +30,7 @@ public class InFilter extends FieldFilter {
3130

3231
@Override
3332
public boolean matches(Document doc) {
34-
FieldValue other = doc.getField(getField());
35-
return other != null && ProtoValues.contains(getValue().getArrayValue(), other.getProto());
33+
Value other = doc.getField(getField());
34+
return other != null && ProtoValues.contains(getValue().getArrayValue(), other);
3635
}
3736
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/OrderBy.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
import com.google.firebase.firestore.model.Document;
1818
import com.google.firebase.firestore.model.FieldPath;
19-
import com.google.firebase.firestore.model.value.FieldValue;
19+
import com.google.firebase.firestore.model.value.ProtoValues;
2020
import com.google.firebase.firestore.util.Assert;
21+
import com.google.firestore.v1.Value;
2122

2223
/** Represents a sort order for a Firestore Query */
2324
public class OrderBy {
@@ -61,11 +62,11 @@ int compare(Document d1, Document d2) {
6162
if (field.equals(FieldPath.KEY_PATH)) {
6263
return direction.getComparisonModifier() * d1.getKey().compareTo(d2.getKey());
6364
} else {
64-
FieldValue v1 = d1.getField(field);
65-
FieldValue v2 = d2.getField(field);
65+
Value v1 = d1.getField(field);
66+
Value v2 = d2.getField(field);
6667
Assert.hardAssert(
6768
v1 != null && v2 != null, "Trying to compare documents on fields that don't exist.");
68-
return direction.getComparisonModifier() * v1.compareTo(v2);
69+
return direction.getComparisonModifier() * ProtoValues.compare(v1, v2);
6970
}
7071
}
7172

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
19-
import com.google.firebase.firestore.model.value.FieldValue;
2019
import com.google.firebase.firestore.model.value.ObjectValue;
2120
import com.google.firestore.v1.Value;
2221
import java.util.Comparator;
@@ -63,15 +62,10 @@ public ObjectValue getData() {
6362
return objectValue;
6463
}
6564

66-
public @Nullable FieldValue getField(FieldPath path) {
65+
public @Nullable Value getField(FieldPath path) {
6766
return objectValue.get(path);
6867
}
6968

70-
public @Nullable Value getFieldProto(FieldPath path) {
71-
FieldValue fieldValue = getField(path);
72-
return fieldValue != null ? fieldValue.getProto() : null;
73-
}
74-
7569
public boolean hasLocalMutations() {
7670
return documentState.equals(DocumentState.LOCAL_MUTATIONS);
7771
}

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import com.google.firebase.firestore.model.MaybeDocument;
2525
import com.google.firebase.firestore.model.SnapshotVersion;
2626
import com.google.firebase.firestore.model.UnknownDocument;
27-
import com.google.firebase.firestore.model.value.FieldValue;
2827
import com.google.firebase.firestore.model.value.ObjectValue;
28+
import com.google.firestore.v1.Value;
2929

3030
/**
3131
* A mutation that modifies fields of the document at the given key with the given values. The
@@ -154,11 +154,11 @@ private ObjectValue patchObject(ObjectValue obj) {
154154
ObjectValue.Builder builder = obj.toBuilder();
155155
for (FieldPath path : mask.getMask()) {
156156
if (!path.isEmpty()) {
157-
FieldValue newValue = value.get(path);
157+
Value newValue = value.get(path);
158158
if (newValue == null) {
159159
builder.delete(path);
160160
} else {
161-
builder.set(path, newValue.getProto());
161+
builder.set(path, newValue);
162162
}
163163
}
164164
}

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/TransformMutation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public ObjectValue extractBaseValue(@Nullable MaybeDocument maybeDoc) {
129129
for (FieldTransform transform : fieldTransforms) {
130130
Value existingValue = null;
131131
if (maybeDoc instanceof Document) {
132-
existingValue = ((Document) maybeDoc).getFieldProto(transform.getFieldPath());
132+
existingValue = ((Document) maybeDoc).getField(transform.getFieldPath());
133133
}
134134

135135
Value coercedValue = transform.getOperation().computeBaseValue(existingValue);
@@ -180,7 +180,7 @@ private List<Value> serverTransformResults(
180180

181181
Value previousValue = null;
182182
if (baseDoc instanceof Document) {
183-
previousValue = ((Document) baseDoc).getFieldProto(fieldTransform.getFieldPath());
183+
previousValue = ((Document) baseDoc).getField(fieldTransform.getFieldPath());
184184
}
185185

186186
transformResults.add(
@@ -207,14 +207,14 @@ private List<Value> localTransformResults(
207207

208208
Value previousValue = null;
209209
if (maybeDoc instanceof Document) {
210-
previousValue = ((Document) maybeDoc).getFieldProto(fieldTransform.getFieldPath());
210+
previousValue = ((Document) maybeDoc).getField(fieldTransform.getFieldPath());
211211
}
212212

213213
if (previousValue == null && baseDoc instanceof Document) {
214214
// If the current document does not contain a value for the mutated field, use the value
215215
// that existed before applying this mutation batch. This solves an edge case where a
216216
// PatchMutation clears the values in a nested map before the TransformMutation is applied.
217-
previousValue = ((Document) baseDoc).getFieldProto(fieldTransform.getFieldPath());
217+
previousValue = ((Document) baseDoc).getField(fieldTransform.getFieldPath());
218218
}
219219

220220
transformResults.add(transform.applyToLocalView(previousValue, localWriteTime));

firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/BlobValue.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/BooleanValue.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

firebase-firestore/src/main/java/com/google/firebase/firestore/model/value/FieldValue.java

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,91 +14,20 @@
1414

1515
package com.google.firebase.firestore.model.value;
1616

17-
import static com.google.firebase.firestore.util.Assert.fail;
18-
1917
import androidx.annotation.NonNull;
20-
import androidx.annotation.Nullable;
2118
import com.google.firestore.v1.Value;
2219

2320
/**
2421
* Represents a FieldValue that is backed by a single Firestore V1 Value proto and implements
2522
* Firestore's Value semantics for ordering and equality.
26-
*
27-
* <p>Supported types are:
28-
*
29-
* <ul>
30-
* <li>Null
31-
* <li>Boolean
32-
* <li>Long
33-
* <li>Double
34-
* <li>Timestamp
35-
* <li>ServerTimestamp (a sentinel used in uncommitted writes)
36-
* <li>String
37-
* <li>Binary
38-
* <li>(Document) References
39-
* <li>GeoPoint
40-
* <li>Array
41-
* <li>Object
42-
* </ul>
4323
*/
4424
public class FieldValue implements Comparable<FieldValue> {
45-
/** The order of types in Firestore; this order is defined by the backend. */
46-
static final int TYPE_ORDER_NULL = 0;
47-
48-
static final int TYPE_ORDER_BOOLEAN = 1;
49-
static final int TYPE_ORDER_NUMBER = 2;
50-
static final int TYPE_ORDER_TIMESTAMP = 3;
51-
static final int TYPE_ORDER_STRING = 4;
52-
static final int TYPE_ORDER_BLOB = 5;
53-
static final int TYPE_ORDER_REFERENCE = 6;
54-
static final int TYPE_ORDER_GEOPOINT = 7;
55-
static final int TYPE_ORDER_ARRAY = 8;
56-
static final int TYPE_ORDER_OBJECT = 9;
57-
5825
final Value internalValue;
5926

60-
FieldValue(Value value) {
27+
public FieldValue(Value value) {
6128
this.internalValue = value;
6229
}
6330

64-
/** Creates a new FieldValue based on the Protobuf Value. */
65-
// TODO(mrschmidt): Unify with UserDataReader.parseScalarValue()
66-
public static @Nullable FieldValue valueOf(@Nullable Value value) {
67-
if (value == null) {
68-
return null;
69-
}
70-
71-
switch (value.getValueTypeCase()) {
72-
case NULL_VALUE:
73-
return new FieldValue(value);
74-
case BOOLEAN_VALUE:
75-
return new BooleanValue(value);
76-
case INTEGER_VALUE:
77-
return new FieldValue(value);
78-
case DOUBLE_VALUE:
79-
return new FieldValue(value);
80-
case TIMESTAMP_VALUE:
81-
return new TimestampValue(value);
82-
case STRING_VALUE:
83-
return new StringValue(value);
84-
case BYTES_VALUE:
85-
return new BlobValue(value);
86-
case REFERENCE_VALUE:
87-
return new FieldValue(value);
88-
case GEO_POINT_VALUE:
89-
return new GeoPointValue(value);
90-
case ARRAY_VALUE:
91-
return new FieldValue(value);
92-
case MAP_VALUE:
93-
if (ServerTimestampValue.isServerTimestamp(value)) {
94-
return new ServerTimestampValue(value);
95-
}
96-
return new ObjectValue(value);
97-
default:
98-
throw fail("Invlaid value type: %s", value.getValueTypeCase());
99-
}
100-
}
101-
10231
/** Returns Firestore Value Protobuf that backs this FieldValuee */
10332
public Value getProto() {
10433
return internalValue;

0 commit comments

Comments
 (0)