Skip to content

Commit 66d722f

Browse files
Format
1 parent 7bdc88a commit 66d722f

File tree

1 file changed

+26
-29
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/model/value

1 file changed

+26
-29
lines changed

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.google.firestore.v1.ArrayValue;
2323
import com.google.firestore.v1.MapValue;
2424
import com.google.firestore.v1.Value;
25+
import com.google.protobuf.Timestamp;
26+
import com.google.type.LatLng;
2527
import java.util.Iterator;
2628
import java.util.List;
2729
import java.util.Map;
@@ -148,19 +150,19 @@ public static int compare(Value left, Value right) {
148150
case FieldValue.TYPE_ORDER_NUMBER:
149151
return compareNumbers(left, right);
150152
case FieldValue.TYPE_ORDER_TIMESTAMP:
151-
return compareTimestamps(left, right);
153+
return compareTimestamps(left.getTimestampValue(), right.getTimestampValue());
152154
case FieldValue.TYPE_ORDER_STRING:
153155
return left.getStringValue().compareTo(right.getStringValue());
154156
case FieldValue.TYPE_ORDER_BLOB:
155157
return Util.compareByteStrings(left.getBytesValue(), right.getBytesValue());
156158
case FieldValue.TYPE_ORDER_REFERENCE:
157-
return compareReferences(left, right);
159+
return compareReferences(left.getReferenceValue(), right.getReferenceValue());
158160
case FieldValue.TYPE_ORDER_GEOPOINT:
159-
return compareGeoPoints(left, right);
161+
return compareGeoPoints(left.getGeoPointValue(), right.getGeoPointValue());
160162
case FieldValue.TYPE_ORDER_ARRAY:
161-
return compareArrays(left, right);
163+
return compareArrays(left.getArrayValue(), right.getArrayValue());
162164
case FieldValue.TYPE_ORDER_OBJECT:
163-
return compareMaps(left, right);
165+
return compareMaps(left.getMapValue(), right.getMapValue());
164166
default:
165167
throw fail("Invalid value type: " + leftType);
166168
}
@@ -186,18 +188,18 @@ private static int compareNumbers(Value left, Value right) {
186188
throw fail("Unexpected values: %s vs %s", left, right);
187189
}
188190

189-
private static int compareTimestamps(Value left, Value right) {
190-
if (left.getTimestampValue().getSeconds() == right.getTimestampValue().getSeconds()) {
191-
return Integer.signum(
192-
left.getTimestampValue().getNanos() - right.getTimestampValue().getNanos());
191+
private static int compareTimestamps(Timestamp left, Timestamp right) {
192+
int cmp = Util.compareLongs(left.getSeconds(), right.getSeconds());
193+
if (cmp != 0) {
194+
return cmp;
193195
}
194-
return Long.signum(
195-
left.getTimestampValue().getSeconds() - right.getTimestampValue().getSeconds());
196+
197+
return Util.compareIntegers(left.getNanos(), right.getNanos());
196198
}
197199

198-
private static int compareReferences(Value left, Value right) {
199-
List<String> leftSegments = Splitter.on('/').splitToList(left.getReferenceValue());
200-
List<String> rightSegments = Splitter.on('/').splitToList(right.getReferenceValue());
200+
private static int compareReferences(String leftPath, String rightPath) {
201+
List<String> leftSegments = Splitter.on('/').splitToList(leftPath);
202+
List<String> rightSegments = Splitter.on('/').splitToList(rightPath);
201203
int minLength = Math.min(leftSegments.size(), rightSegments.size());
202204
for (int i = 0; i < minLength; i++) {
203205
int cmp = leftSegments.get(i).compareTo(rightSegments.get(i));
@@ -208,35 +210,30 @@ private static int compareReferences(Value left, Value right) {
208210
return Util.compareIntegers(leftSegments.size(), rightSegments.size());
209211
}
210212

211-
private static int compareGeoPoints(Value left, Value right) {
212-
int comparison =
213-
Util.compareDoubles(
214-
left.getGeoPointValue().getLatitude(), right.getGeoPointValue().getLatitude());
213+
private static int compareGeoPoints(LatLng left, LatLng right) {
214+
int comparison = Util.compareDoubles(left.getLatitude(), right.getLatitude());
215215
if (comparison == 0) {
216-
return Util.compareDoubles(
217-
left.getGeoPointValue().getLongitude(), right.getGeoPointValue().getLongitude());
216+
return Util.compareDoubles(left.getLongitude(), right.getLongitude());
218217
}
219218
return comparison;
220219
}
221220

222-
private static int compareArrays(Value left, Value right) {
223-
int minLength =
224-
Math.min(left.getArrayValue().getValuesCount(), right.getArrayValue().getValuesCount());
221+
private static int compareArrays(ArrayValue left, ArrayValue right) {
222+
int minLength = Math.min(left.getValuesCount(), right.getValuesCount());
225223
for (int i = 0; i < minLength; i++) {
226-
int cmp = compare(left.getArrayValue().getValues(i), right.getArrayValue().getValues(i));
224+
int cmp = compare(left.getValues(i), right.getValues(i));
227225
if (cmp != 0) {
228226
return cmp;
229227
}
230228
}
231-
return Util.compareIntegers(
232-
left.getArrayValue().getValuesCount(), right.getArrayValue().getValuesCount());
229+
return Util.compareIntegers(left.getValuesCount(), right.getValuesCount());
233230
}
234231

235-
private static int compareMaps(Value left, Value right) {
232+
private static int compareMaps(MapValue left, MapValue right) {
236233
Iterator<Map.Entry<String, Value>> iterator1 =
237-
new TreeMap<>(left.getMapValue().getFieldsMap()).entrySet().iterator();
234+
new TreeMap<>(left.getFieldsMap()).entrySet().iterator();
238235
Iterator<Map.Entry<String, Value>> iterator2 =
239-
new TreeMap<>(right.getMapValue().getFieldsMap()).entrySet().iterator();
236+
new TreeMap<>(right.getFieldsMap()).entrySet().iterator();
240237
while (iterator1.hasNext() && iterator2.hasNext()) {
241238
Map.Entry<String, Value> entry1 = iterator1.next();
242239
Map.Entry<String, Value> entry2 = iterator2.next();

0 commit comments

Comments
 (0)