Skip to content

Commit 666458a

Browse files
Merge branch 'mrschmidt/droprest' into mrschmidt/dropall
2 parents 4669589 + 2ce8a22 commit 666458a

File tree

7 files changed

+52
-43
lines changed

7 files changed

+52
-43
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ public String canonicalString() {
6565
} else {
6666
builder.append("a:");
6767
}
68+
boolean first = true;
6869
for (Value indexComponent : position) {
70+
if (!first) {
71+
builder.append(",");
72+
}
73+
first = false;
6974
builder.append(ProtoValues.canonicalId(indexComponent));
7075
}
7176
return builder.toString();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424

2525
/** Filter that matches on key fields (i.e. '__name__'). */
2626
public class KeyFieldFilter extends FieldFilter {
27+
private final DocumentKey key;
28+
2729
KeyFieldFilter(FieldPath field, Operator operator, Value value) {
2830
super(field, operator, value);
2931
hardAssert(ProtoValues.isReferenceValue(value), "KeyFieldFilter expects a ReferenceValue");
32+
key = DocumentKey.fromName(getValue().getReferenceValue());
3033
}
3134

3235
@Override
3336
public boolean matches(Document doc) {
34-
DocumentKey referencedKey = DocumentKey.fromName(getValue().getReferenceValue());
35-
int comparator = doc.getKey().compareTo(referencedKey);
37+
int comparator = doc.getKey().compareTo(key);
3638
return this.matchesComparison(comparator);
3739
}
3840
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
import com.google.firebase.firestore.model.FieldPath;
2222
import com.google.firebase.firestore.model.value.ProtoValues;
2323
import com.google.firestore.v1.Value;
24+
import java.util.ArrayList;
25+
import java.util.List;
2426

2527
public class KeyFieldInFilter extends FieldFilter {
28+
private final List<DocumentKey> keys = new ArrayList<>();
29+
2630
KeyFieldInFilter(FieldPath field, Value value) {
2731
super(field, Operator.IN, value);
32+
2833
hardAssert(ProtoValues.isArray(value), "KeyFieldInFilter expects an ArrayValue");
2934
for (Value element : value.getArrayValue().getValuesList()) {
3035
hardAssert(
3136
ProtoValues.isReferenceValue(element),
3237
"Comparing on key with IN, but an array value was not a ReferenceValue");
38+
keys.add(DocumentKey.fromName(element.getReferenceValue()));
3339
}
3440
}
3541

3642
@Override
3743
public boolean matches(Document doc) {
38-
for (Value refValue : getValue().getArrayValue().getValuesList()) {
39-
DocumentKey referencedKey = DocumentKey.fromName(refValue.getReferenceValue());
40-
if (doc.getKey().equals(referencedKey)) {
41-
return true;
42-
}
43-
}
44-
return false;
44+
return keys.contains(doc.getKey());
4545
}
4646
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

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

17+
import static com.google.firebase.firestore.model.value.ProtoValues.isDouble;
18+
import static com.google.firebase.firestore.model.value.ProtoValues.isInteger;
1719
import static com.google.firebase.firestore.util.Assert.fail;
1820
import static com.google.firebase.firestore.util.Assert.hardAssert;
1921

@@ -120,12 +122,4 @@ private long operandAsLong() {
120122
+ operand.getClass().getCanonicalName());
121123
}
122124
}
123-
124-
private boolean isInteger(@Nullable Value value) {
125-
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.INTEGER_VALUE;
126-
}
127-
128-
private boolean isDouble(@Nullable Value value) {
129-
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.DOUBLE_VALUE;
130-
}
131125
}

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ public class ProtoValues {
4242
Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
4343

4444
/** The order of types in Firestore; this order is defined by the backend. */
45-
private static final int TYPE_ORDER_NULL = 0;
46-
47-
private static final int TYPE_ORDER_BOOLEAN = 1;
48-
private static final int TYPE_ORDER_NUMBER = 2;
49-
private static final int TYPE_ORDER_TIMESTAMP = 3;
50-
private static final int TYPE_ORDER_STRING = 4;
51-
private static final int TYPE_ORDER_BLOB = 5;
52-
private static final int TYPE_ORDER_REFERENCE = 6;
53-
private static final int TYPE_ORDER_GEOPOINT = 7;
54-
private static final int TYPE_ORDER_ARRAY = 8;
55-
private static final int TYPE_ORDER_MAP = 9;
45+
public static final int TYPE_ORDER_NULL = 0;
46+
47+
public static final int TYPE_ORDER_BOOLEAN = 1;
48+
public static final int TYPE_ORDER_NUMBER = 2;
49+
public static final int TYPE_ORDER_TIMESTAMP = 3;
50+
public static final int TYPE_ORDER_STRING = 4;
51+
public static final int TYPE_ORDER_BLOB = 5;
52+
public static final int TYPE_ORDER_REFERENCE = 6;
53+
public static final int TYPE_ORDER_GEOPOINT = 7;
54+
public static final int TYPE_ORDER_ARRAY = 8;
55+
public static final int TYPE_ORDER_MAP = 9;
5656

5757
/** Returns the backend's type order of the given Value type. */
5858
public static int typeOrder(Value value) {
@@ -178,8 +178,8 @@ private static boolean objectEquals(Value left, Value right) {
178178

179179
/** Returns true if the Value list contains the specified element. */
180180
public static boolean contains(ArrayValueOrBuilder haystack, Value needle) {
181-
for (Value haystackEl : haystack.getValuesList()) {
182-
if (equals(haystackEl, needle)) {
181+
for (Value haystackElement : haystack.getValuesList()) {
182+
if (equals(haystackElement, needle)) {
183183
return true;
184184
}
185185
}
@@ -410,11 +410,19 @@ private static void canonifyArray(StringBuilder builder, ArrayValue arrayValue)
410410
builder.append("]");
411411
}
412412

413+
/** Returns true if `value` is either a INTEGER_VALUE. */
414+
public static boolean isInteger(@Nullable Value value) {
415+
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.INTEGER_VALUE;
416+
}
417+
418+
/** Returns true if `value` is either a DOUBLE_VALUE. */
419+
public static boolean isDouble(@Nullable Value value) {
420+
return value != null && value.getValueTypeCase() == Value.ValueTypeCase.DOUBLE_VALUE;
421+
}
422+
413423
/** Returns true if `value` is either a INTEGER_VALUE or a DOUBLE_VALUE. */
414424
public static boolean isNumber(@Nullable Value value) {
415-
return value != null
416-
&& (value.getValueTypeCase() == Value.ValueTypeCase.INTEGER_VALUE
417-
|| value.getValueTypeCase() == Value.ValueTypeCase.DOUBLE_VALUE);
425+
return isInteger(value) || isDouble(value);
418426
}
419427

420428
/** Returns true if `value` is an ARRAY_VALUE. */

firebase-firestore/src/test/java/com/google/firebase/firestore/UserDataWriterTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testConvertsBooleanValue() {
6363
List<Boolean> testCases = asList(true, false);
6464
for (Boolean b : testCases) {
6565
FieldValue value = wrap(b);
66-
assertValueType(value, Value.ValueTypeCase.BOOLEAN_VALUE);
66+
assertValueType(Value.ValueTypeCase.BOOLEAN_VALUE, value);
6767
Object convertedValue = convertValue(value);
6868
assertEquals(b, convertedValue);
6969
}
@@ -74,7 +74,7 @@ public void testConvertsIntegerValue() {
7474
List<Integer> testCases = asList(Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE);
7575
for (Integer i : testCases) {
7676
FieldValue value = wrap(i);
77-
assertValueType(value, Value.ValueTypeCase.INTEGER_VALUE);
77+
assertValueType(Value.ValueTypeCase.INTEGER_VALUE, value);
7878
Object convertedValue = convertValue(value);
7979
assertEquals(i.longValue(), convertedValue);
8080
}
@@ -94,7 +94,7 @@ public void testConvertsLongValue() {
9494
Long.MAX_VALUE);
9595
for (Long l : testCases) {
9696
FieldValue value = wrap(l);
97-
assertValueType(value, Value.ValueTypeCase.INTEGER_VALUE);
97+
assertValueType(Value.ValueTypeCase.INTEGER_VALUE, value);
9898
Object convertedValue = convertValue(value);
9999
assertEquals(l, convertedValue);
100100
}
@@ -116,7 +116,7 @@ public void testConvertsFloatValue() {
116116
Float.MAX_VALUE);
117117
for (Float f : testCases) {
118118
FieldValue value = wrap(f);
119-
assertValueType(value, Value.ValueTypeCase.DOUBLE_VALUE);
119+
assertValueType(Value.ValueTypeCase.DOUBLE_VALUE, value);
120120
Object convertedValue = convertValue(value);
121121
assertEquals(f.doubleValue(), convertedValue);
122122
}
@@ -147,7 +147,7 @@ public void testConvertsDoubleValue() {
147147
Double.NaN);
148148
for (Double d : testCases) {
149149
FieldValue value = wrap(d);
150-
assertValueType(value, Value.ValueTypeCase.DOUBLE_VALUE);
150+
assertValueType(Value.ValueTypeCase.DOUBLE_VALUE, value);
151151
Object convertedValue = convertValue(value);
152152
assertEquals(d, convertedValue);
153153
}
@@ -163,7 +163,7 @@ public void testConvertsDateValue() {
163163
List<Date> testCases = asList(new Date(0), new Date(1356048000000L));
164164
for (Date d : testCases) {
165165
FieldValue value = wrap(d);
166-
assertValueType(value, Value.ValueTypeCase.TIMESTAMP_VALUE);
166+
assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
167167
Object convertedValue = dateWriter.convertValue(value.getProto());
168168
assertEquals(d, convertedValue);
169169
}
@@ -174,7 +174,7 @@ public void testConvertsTimestampValue() {
174174
List<Timestamp> testCases = asList(new Timestamp(0, 0), new Timestamp(1356048000L, 0));
175175
for (Timestamp t : testCases) {
176176
FieldValue value = wrap(t);
177-
assertValueType(value, Value.ValueTypeCase.TIMESTAMP_VALUE);
177+
assertValueType(Value.ValueTypeCase.TIMESTAMP_VALUE, value);
178178
Object convertedValue = convertValue(value);
179179
assertEquals(t, convertedValue);
180180
}
@@ -287,7 +287,7 @@ private Object convertValue(FieldValue value) {
287287
return writer.convertValue(value.getProto());
288288
}
289289

290-
private void assertValueType(FieldValue value, Value.ValueTypeCase booleanValue) {
290+
private void assertValueType(Value.ValueTypeCase booleanValue, FieldValue value) {
291291
assertEquals(booleanValue, value.getProto().getValueTypeCase());
292292
}
293293
}

firebase-firestore/src/test/java/com/google/firebase/firestore/core/QueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,13 @@ public void testCanonicalIdsAreStable() {
604604
.orderBy(orderBy("a"))
605605
.startAt(
606606
new Bound(Arrays.asList(valueOf("foo"), valueOf(Arrays.asList(1, 2, 3))), true)),
607-
"collection|f:|ob:aasc__name__asc|lb:b:foo[1,2,3]");
607+
"collection|f:|ob:aasc__name__asc|lb:b:foo,[1,2,3]");
608608
assertCanonicalId(
609609
baseQuery
610610
.orderBy(orderBy("a"))
611611
.endAt(
612612
new Bound(Arrays.asList(valueOf("foo"), valueOf(Arrays.asList(1, 2, 3))), false)),
613-
"collection|f:|ob:aasc__name__asc|ub:a:foo[1,2,3]");
613+
"collection|f:|ob:aasc__name__asc|ub:a:foo,[1,2,3]");
614614
assertCanonicalId(baseQuery.limitToFirst(5), "collection|f:|ob:__name__asc|l:5");
615615
assertCanonicalId(baseQuery.limitToLast(5), "collection|f:|ob:__name__desc|l:5");
616616
}

0 commit comments

Comments
 (0)