Skip to content

Commit bcbf83f

Browse files
committed
Merge branch 'tomandersen/pipelines' into tomandersen/pipelines-evaluate
# Conflicts: # firebase-firestore/src/main/java/com/google/firebase/firestore/model/Values.kt
2 parents 64f26ea + 5eb6a01 commit bcbf83f

File tree

9 files changed

+52
-121
lines changed

9 files changed

+52
-121
lines changed

firebase-firestore/src/main/java/com/google/cloud/datastore/core/number/NumberComparisonHelper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static int firestoreCompareDoubleWithLong(double doubleValue, long longVa
5050
}
5151

5252
long doubleAsLong = (long) doubleValue;
53-
int cmp = compareLongs(doubleAsLong, longValue);
53+
int cmp = Long.compare(doubleAsLong, longValue);
5454
if (cmp != 0) {
5555
return cmp;
5656
}
@@ -60,11 +60,6 @@ public static int firestoreCompareDoubleWithLong(double doubleValue, long longVa
6060
return firestoreCompareDoubles(doubleValue, longAsDouble);
6161
}
6262

63-
/** Compares longs. */
64-
public static int compareLongs(long leftLong, long rightLong) {
65-
return Long.compare(leftLong, rightLong);
66-
}
67-
6863
/**
6964
* Compares doubles with Firestore query semantics: NaN precedes all other numbers and equals
7065
* itself, all zeroes are equal.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
package com.google.firebase.firestore;
1616

17+
import static com.google.cloud.datastore.core.number.NumberComparisonHelper.firestoreCompareDoubles;
18+
1719
import androidx.annotation.NonNull;
1820
import androidx.annotation.Nullable;
19-
import com.google.firebase.firestore.util.Util;
2021

2122
/** Immutable class representing a {@code GeoPoint} in Cloud Firestore */
2223
public class GeoPoint implements Comparable<GeoPoint> {
@@ -52,9 +53,9 @@ public double getLongitude() {
5253

5354
@Override
5455
public int compareTo(@NonNull GeoPoint other) {
55-
int comparison = Util.compareDoubles(latitude, other.latitude);
56+
int comparison = firestoreCompareDoubles(latitude, other.latitude);
5657
if (comparison == 0) {
57-
return Util.compareDoubles(longitude, other.longitude);
58+
return firestoreCompareDoubles(longitude, other.longitude);
5859
} else {
5960
return comparison;
6061
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static com.google.firebase.firestore.core.Query.LimitType.LIMIT_TO_FIRST;
1818
import static com.google.firebase.firestore.core.Query.LimitType.LIMIT_TO_LAST;
1919
import static com.google.firebase.firestore.util.Assert.hardAssert;
20-
import static com.google.firebase.firestore.util.Util.compareIntegers;
2120

2221
import androidx.annotation.Nullable;
2322
import com.google.firebase.database.collection.ImmutableSortedMap;
@@ -301,7 +300,8 @@ public ViewChange applyChanges(
301300
Collections.sort(
302301
viewChanges,
303302
(DocumentViewChange o1, DocumentViewChange o2) -> {
304-
int typeComp = compareIntegers(View.changeTypeOrder(o1), View.changeTypeOrder(o2));
303+
int i1 = View.changeTypeOrder(o1);
304+
int typeComp = Integer.compare(i1, View.changeTypeOrder(o2));
305305
if (typeComp != 0) {
306306
return typeComp;
307307
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/DocumentReference.java

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

1515
package com.google.firebase.firestore.local;
1616

17-
import static com.google.firebase.firestore.util.Util.compareIntegers;
18-
1917
import com.google.firebase.firestore.model.DocumentKey;
2018
import java.util.Comparator;
2119

@@ -60,12 +58,12 @@ int getId() {
6058
return keyComp;
6159
}
6260

63-
return compareIntegers(o1.targetOrBatchId, o2.targetOrBatchId);
61+
return Integer.compare(o1.targetOrBatchId, o2.targetOrBatchId);
6462
};
6563

6664
static final Comparator<DocumentReference> BY_TARGET =
6765
(o1, o2) -> {
68-
int targetComp = compareIntegers(o1.targetOrBatchId, o2.targetOrBatchId);
66+
int targetComp = Integer.compare(o1.targetOrBatchId, o2.targetOrBatchId);
6967

7068
if (targetComp != 0) {
7169
return targetComp;

firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryMutationQueue.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.firebase.firestore.model.mutation.Mutation;
2929
import com.google.firebase.firestore.model.mutation.MutationBatch;
3030
import com.google.firebase.firestore.remote.WriteStream;
31-
import com.google.firebase.firestore.util.Util;
3231
import com.google.protobuf.ByteString;
3332
import java.util.ArrayList;
3433
import java.util.Collections;
@@ -216,7 +215,7 @@ public List<MutationBatch> getAllMutationBatchesAffectingDocumentKey(DocumentKey
216215
public List<MutationBatch> getAllMutationBatchesAffectingDocumentKeys(
217216
Iterable<DocumentKey> documentKeys) {
218217
ImmutableSortedSet<Integer> uniqueBatchIDs =
219-
new ImmutableSortedSet<Integer>(emptyList(), Util.comparator());
218+
new ImmutableSortedSet<Integer>(emptyList(), Comparable::compareTo);
220219

221220
for (DocumentKey key : documentKeys) {
222221
DocumentReference start = new DocumentReference(key, 0);
@@ -255,7 +254,7 @@ public List<MutationBatch> getAllMutationBatchesAffectingQuery(Query query) {
255254

256255
// Find unique batchIDs referenced by all documents potentially matching the query.
257256
ImmutableSortedSet<Integer> uniqueBatchIDs =
258-
new ImmutableSortedSet<Integer>(emptyList(), Util.comparator());
257+
new ImmutableSortedSet<Integer>(emptyList(), Comparable::compareTo);
259258

260259
Iterator<DocumentReference> iterator = batchesByDocumentKey.iteratorFrom(start);
261260
while (iterator.hasNext()) {

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteMutationQueue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.firebase.firestore.model.mutation.MutationBatch;
3131
import com.google.firebase.firestore.remote.WriteStream;
3232
import com.google.firebase.firestore.util.Consumer;
33-
import com.google.firebase.firestore.util.Util;
3433
import com.google.protobuf.ByteString;
3534
import com.google.protobuf.InvalidProtocolBufferException;
3635
import com.google.protobuf.MessageLite;
@@ -324,7 +323,7 @@ public List<MutationBatch> getAllMutationBatchesAffectingDocumentKeys(
324323
Collections.sort(
325324
result,
326325
(MutationBatch lhs, MutationBatch rhs) ->
327-
Util.compareIntegers(lhs.getBatchId(), rhs.getBatchId()));
326+
Integer.compare(lhs.getBatchId(), rhs.getBatchId()));
328327
}
329328
return result;
330329
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public int compareTo(@NonNull B o) {
107107
}
108108
i++;
109109
}
110-
return Util.compareIntegers(myLength, theirLength);
110+
return Integer.compare(myLength, theirLength);
111111
}
112112

113113
private static int compareSegments(String lhs, String rhs) {

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Values.kt

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414
package com.google.firebase.firestore.model
1515

16+
import com.google.cloud.datastore.core.number.NumberComparisonHelper.firestoreCompareDoubleWithLong
17+
import com.google.cloud.datastore.core.number.NumberComparisonHelper.firestoreCompareDoubles
1618
import com.google.firebase.firestore.Blob
1719
import com.google.firebase.firestore.DocumentReference
1820
import com.google.firebase.firestore.GeoPoint
@@ -28,7 +30,6 @@ import com.google.protobuf.ByteString
2830
import com.google.protobuf.NullValue
2931
import com.google.protobuf.Timestamp
3032
import com.google.type.LatLng
31-
import java.lang.Double.doubleToLongBits
3233
import java.util.Date
3334
import java.util.TreeMap
3435
import kotlin.math.min
@@ -175,42 +176,40 @@ internal object Values {
175176
ValueTypeCase.INTEGER_VALUE ->
176177
when (right.valueTypeCase) {
177178
ValueTypeCase.INTEGER_VALUE -> left.integerValue == right.integerValue
178-
ValueTypeCase.DOUBLE_VALUE -> right.doubleValue.compareTo(left.integerValue) == 0
179+
ValueTypeCase.DOUBLE_VALUE ->
180+
firestoreCompareDoubleWithLong(right.doubleValue, left.integerValue) == 0
179181
else -> false
180182
}
181183
ValueTypeCase.DOUBLE_VALUE ->
182184
when (right.valueTypeCase) {
183185
ValueTypeCase.INTEGER_VALUE ->
184-
compareDoubleWithLong(left.doubleValue, right.integerValue) == 0
186+
firestoreCompareDoubleWithLong(left.doubleValue, right.integerValue) == 0
185187
ValueTypeCase.DOUBLE_VALUE ->
186-
doubleToLongBits(left.doubleValue) == doubleToLongBits(right.doubleValue)
188+
firestoreCompareDoubles(left.doubleValue, right.doubleValue) == 0
187189
else -> false
188190
}
189191
else -> false
190192
}
191193

192-
private fun compareDoubleWithLong(double: Double, long: Long): Int =
193-
if (double.isNaN()) -1 else double.compareTo(long)
194+
private fun strictArrayEquals(left: Value, right: Value): Boolean? {
195+
val leftArray = left.arrayValue
196+
val rightArray = right.arrayValue
194197

195-
private fun strictArrayEquals(left: Value, right: Value): Boolean? {
196-
val leftArray = left.arrayValue
197-
val rightArray = right.arrayValue
198-
199-
if (leftArray.valuesCount != rightArray.valuesCount) {
200-
return false
201-
}
198+
if (leftArray.valuesCount != rightArray.valuesCount) {
199+
return false
200+
}
202201

203-
var foundNull = false
204-
for (i in 0 until leftArray.valuesCount) {
205-
val equals = strictEquals(leftArray.getValues(i), rightArray.getValues(i))
206-
if (equals === null) {
207-
foundNull = true
208-
} else if (!equals) {
209-
return false
210-
}
202+
var foundNull = false
203+
for (i in 0 until leftArray.valuesCount) {
204+
val equals = strictEquals(leftArray.getValues(i), rightArray.getValues(i))
205+
if (equals === null) {
206+
foundNull = true
207+
} else if (!equals) {
208+
return false
209+
}
210+
}
211+
return if (foundNull) null else true
211212
}
212-
return if (foundNull) null else true
213-
}
214213

215214
private fun arrayEquals(left: Value, right: Value): Boolean {
216215
val leftArray = left.arrayValue
@@ -286,7 +285,7 @@ internal object Values {
286285
val rightType = typeOrder(right)
287286

288287
if (leftType != rightType) {
289-
return Util.compareIntegers(leftType, rightType)
288+
return leftType.compareTo(rightType)
290289
}
291290

292291
return compareInternal(leftType, left, right)
@@ -296,7 +295,7 @@ internal object Values {
296295
when (leftType) {
297296
TYPE_ORDER_NULL,
298297
TYPE_ORDER_MAX_VALUE -> 0
299-
TYPE_ORDER_BOOLEAN -> Util.compareBooleans(left.booleanValue, right.booleanValue)
298+
TYPE_ORDER_BOOLEAN -> left.booleanValue.compareTo(right.booleanValue)
300299
TYPE_ORDER_NUMBER -> compareNumbers(left, right)
301300
TYPE_ORDER_TIMESTAMP -> compareTimestamps(left.timestampValue, right.timestampValue)
302301
TYPE_ORDER_SERVER_TIMESTAMP ->
@@ -359,27 +358,27 @@ internal object Values {
359358
private fun compareNumbers(left: Value, right: Value): Int {
360359
if (left.hasDoubleValue()) {
361360
if (right.hasDoubleValue()) {
362-
return Util.compareDoubles(left.doubleValue, right.doubleValue)
361+
return firestoreCompareDoubles(left.doubleValue, right.doubleValue)
363362
} else if (right.hasIntegerValue()) {
364-
return Util.compareMixed(left.doubleValue, right.integerValue)
363+
return firestoreCompareDoubleWithLong(left.doubleValue, right.integerValue)
365364
}
366365
} else if (left.hasIntegerValue()) {
367366
if (right.hasIntegerValue()) {
368-
return Util.compareLongs(left.integerValue, right.integerValue)
367+
return java.lang.Long.compare(left.integerValue, right.integerValue)
369368
} else if (right.hasDoubleValue()) {
370-
return -1 * Util.compareMixed(right.doubleValue, left.integerValue)
369+
return -1 * firestoreCompareDoubleWithLong(right.doubleValue, left.integerValue)
371370
}
372371
}
373372

374373
throw Assert.fail("Unexpected values: %s vs %s", left, right)
375374
}
376375

377376
private fun compareTimestamps(left: Timestamp, right: Timestamp): Int {
378-
val cmp = Util.compareLongs(left.seconds, right.seconds)
377+
val cmp = left.seconds.compareTo(right.seconds)
379378
if (cmp != 0) {
380379
return cmp
381380
}
382-
return Util.compareIntegers(left.nanos, right.nanos)
381+
return left.nanos.compareTo(right.nanos)
383382
}
384383

385384
private fun compareReferences(leftPath: String, rightPath: String): Int {
@@ -393,13 +392,13 @@ internal object Values {
393392
return cmp
394393
}
395394
}
396-
return Util.compareIntegers(leftSegments.size, rightSegments.size)
395+
return leftSegments.size.compareTo(rightSegments.size)
397396
}
398397

399398
private fun compareGeoPoints(left: LatLng, right: LatLng): Int {
400-
val comparison = Util.compareDoubles(left.latitude, right.latitude)
399+
val comparison = firestoreCompareDoubles(left.latitude, right.latitude)
401400
if (comparison == 0) {
402-
return Util.compareDoubles(left.longitude, right.longitude)
401+
return firestoreCompareDoubles(left.longitude, right.longitude)
403402
}
404403
return comparison
405404
}
@@ -412,7 +411,7 @@ internal object Values {
412411
return cmp
413412
}
414413
}
415-
return Util.compareIntegers(left.valuesCount, right.valuesCount)
414+
return left.valuesCount.compareTo(right.valuesCount)
416415
}
417416

418417
private fun compareMaps(left: MapValue, right: MapValue): Int {
@@ -432,7 +431,7 @@ internal object Values {
432431
}
433432

434433
// Only equal if both iterators are exhausted.
435-
return Util.compareBooleans(iterator1.hasNext(), iterator2.hasNext())
434+
return iterator1.hasNext().compareTo(iterator2.hasNext())
436435
}
437436

438437
private fun compareVectors(left: MapValue, right: MapValue): Int {
@@ -443,8 +442,7 @@ internal object Values {
443442
val leftArrayValue = leftMap[VECTOR_MAP_VECTORS_KEY]!!.arrayValue
444443
val rightArrayValue = rightMap[VECTOR_MAP_VECTORS_KEY]!!.arrayValue
445444

446-
val lengthCompare =
447-
Util.compareIntegers(leftArrayValue.valuesCount, rightArrayValue.valuesCount)
445+
val lengthCompare = leftArrayValue.valuesCount.compareTo(rightArrayValue.valuesCount)
448446
if (lengthCompare != 0) {
449447
return lengthCompare
450448
}

0 commit comments

Comments
 (0)