Skip to content

Remove value package, rename ProtoValues #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.DocumentSet;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firebase.firestore.model.ObjectValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.DocumentSet;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.ResourcePath;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firestore.v1.Value;
import java.util.Comparator;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.google.firebase.firestore.FieldPath
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
import com.google.firebase.firestore.TestUtil
import com.google.firebase.firestore.model.value.ObjectValue
import com.google.firebase.firestore.model.ObjectValue
import com.google.firebase.firestore.testutil.TestUtil.wrap
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.ResourcePath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.value.ServerTimestamps;
import com.google.firebase.firestore.model.ServerTimestamps;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.util.Executors;
import com.google.firebase.firestore.util.Util;
import com.google.firestore.v1.ArrayValue;
Expand Down Expand Up @@ -392,10 +392,10 @@ private Value parseDocumentIdValue(Object documentIdValue) {
+ path.length()
+ ").");
}
return ProtoValues.refValue(this.getFirestore().getDatabaseId(), DocumentKey.fromPath(path));
return Values.refValue(this.getFirestore().getDatabaseId(), DocumentKey.fromPath(path));
} else if (documentIdValue instanceof DocumentReference) {
DocumentReference ref = (DocumentReference) documentIdValue;
return ProtoValues.refValue(this.getFirestore().getDatabaseId(), ref.getKey());
return Values.refValue(this.getFirestore().getDatabaseId(), ref.getKey());
} else {
throw new IllegalArgumentException(
"Invalid query. When querying with FieldPath.documentId() you must provide a valid "
Expand Down Expand Up @@ -748,7 +748,7 @@ private Bound boundFromDocumentSnapshot(
// orders), multiple documents could match the position, yielding duplicate results.
for (OrderBy orderBy : query.getOrderBy()) {
if (orderBy.getField().equals(com.google.firebase.firestore.model.FieldPath.KEY_PATH)) {
components.add(ProtoValues.refValue(firestore.getDatabaseId(), document.getKey()));
components.add(Values.refValue(firestore.getDatabaseId(), document.getKey()));
} else {
Value value = document.getField(orderBy.getField());
if (ServerTimestamps.isServerTimestamp(value)) {
Expand Down Expand Up @@ -818,7 +818,7 @@ private Bound boundFromFields(String methodName, Object[] values, boolean before
+ "' is not because it contains an odd number of segments.");
}
DocumentKey key = DocumentKey.fromPath(path);
components.add(ProtoValues.refValue(firestore.getDatabaseId(), key));
components.add(Values.refValue(firestore.getDatabaseId(), key));
} else {
Value wrapped = firestore.getUserDataReader().parseQueryValue(rawValue);
components.add(wrapped);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import com.google.firebase.firestore.core.UserData.ParsedUpdateData;
import com.google.firebase.firestore.model.DatabaseId;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.mutation.ArrayTransformOperation;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.model.mutation.NumericIncrementTransformOperation;
import com.google.firebase.firestore.model.mutation.ServerTimestampOperation;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firebase.firestore.util.Assert;
import com.google.firebase.firestore.util.CustomClassMapper;
import com.google.firebase.firestore.util.Util;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package com.google.firebase.firestore;

import static com.google.firebase.firestore.model.value.ServerTimestamps.getLocalWriteTime;
import static com.google.firebase.firestore.model.value.ServerTimestamps.getPreviousValue;
import static com.google.firebase.firestore.model.value.ServerTimestamps.isServerTimestamp;
import static com.google.firebase.firestore.model.ServerTimestamps.getLocalWriteTime;
import static com.google.firebase.firestore.model.ServerTimestamps.getPreviousValue;
import static com.google.firebase.firestore.model.ServerTimestamps.isServerTimestamp;
import static com.google.firebase.firestore.util.Assert.fail;

import androidx.annotation.RestrictTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@

import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;

/** A Filter that implements the array-contains-any operator. */
public class ArrayContainsAnyFilter extends FieldFilter {
ArrayContainsAnyFilter(FieldPath field, Value value) {
super(field, Operator.ARRAY_CONTAINS_ANY, value);
hardAssert(ProtoValues.isArray(value), "ArrayContainsAnyFilter expects an ArrayValue");
hardAssert(Values.isArray(value), "ArrayContainsAnyFilter expects an ArrayValue");
}

@Override
public boolean matches(Document doc) {
Value other = doc.getField(getField());
if (!ProtoValues.isArray(other)) {
if (!Values.isArray(other)) {
return false;
}
for (Value val : other.getArrayValue().getValuesList()) {
if (ProtoValues.contains(getValue().getArrayValue(), val)) {
if (Values.contains(getValue().getArrayValue(), val)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;

/** A Filter that implements the array-contains operator. */
Expand All @@ -28,6 +28,6 @@ public class ArrayContainsFilter extends FieldFilter {
@Override
public boolean matches(Document doc) {
Value other = doc.getField(getField());
return ProtoValues.isArray(other) && ProtoValues.contains(other.getArrayValue(), getValue());
return Values.isArray(other) && Values.contains(other.getArrayValue(), getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;
import java.util.List;

Expand Down Expand Up @@ -71,7 +71,7 @@ public String canonicalString() {
builder.append(",");
}
first = false;
builder.append(ProtoValues.canonicalId(indexComponent));
builder.append(Values.canonicalId(indexComponent));
}
return builder.toString();
}
Expand All @@ -85,7 +85,7 @@ public boolean sortsBeforeDocument(List<OrderBy> orderBy, Document document) {
Value component = position.get(i);
if (orderByComponent.field.equals(FieldPath.KEY_PATH)) {
hardAssert(
ProtoValues.isReferenceValue(component),
Values.isReferenceValue(component),
"Bound has a non-key value where the key path is being used %s",
component);
comparison =
Expand All @@ -94,7 +94,7 @@ public boolean sortsBeforeDocument(List<OrderBy> orderBy, Document document) {
Value docValue = document.getField(orderByComponent.getField());
hardAssert(
docValue != null, "Field should exist since document matched the orderBy already.");
comparison = ProtoValues.compare(component, docValue);
comparison = Values.compare(component, docValue);
}

if (orderByComponent.getDirection().equals(Direction.DESCENDING)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.util.Assert;
import com.google.firestore.v1.Value;
import java.util.Arrays;
Expand Down Expand Up @@ -70,13 +70,13 @@ public static FieldFilter create(FieldPath path, Operator operator, Value value)
operator.toString() + "queries don't make sense on document keys");
return new KeyFieldFilter(path, operator, value);
}
} else if (ProtoValues.isNullValue(value)) {
} else if (Values.isNullValue(value)) {
if (operator != Filter.Operator.EQUAL) {
throw new IllegalArgumentException(
"Invalid Query. Null supports only equality comparisons (via whereEqualTo()).");
}
return new FieldFilter(path, operator, value);
} else if (ProtoValues.isNanValue(value)) {
} else if (Values.isNanValue(value)) {
if (operator != Filter.Operator.EQUAL) {
throw new IllegalArgumentException(
"Invalid Query. NaN supports only equality comparisons (via whereEqualTo()).");
Expand All @@ -98,8 +98,8 @@ public boolean matches(Document doc) {
Value other = doc.getField(field);
// Only compare types with matching backend order (such as double and int).
return other != null
&& ProtoValues.typeOrder(other) == ProtoValues.typeOrder(value)
&& this.matchesComparison(ProtoValues.compare(other, value));
&& Values.typeOrder(other) == Values.typeOrder(value)
&& this.matchesComparison(Values.compare(other, value));
}

protected boolean matchesComparison(int comp) {
Expand Down Expand Up @@ -132,9 +132,7 @@ public boolean isInequality() {
public String getCanonicalId() {
// TODO: Technically, this won't be unique if two values have the same description,
// such as the int 3 and the string "3". So we should add the types in here somehow, too.
return getField().canonicalString()
+ getOperator().toString()
+ ProtoValues.canonicalId(getValue());
return getField().canonicalString() + getOperator().toString() + Values.canonicalId(getValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;

/** A Filter that implements the IN operator. */
public class InFilter extends FieldFilter {
InFilter(FieldPath field, Value value) {
super(field, Operator.IN, value);
hardAssert(ProtoValues.isArray(value), "InFilter expects an ArrayValue");
hardAssert(Values.isArray(value), "InFilter expects an ArrayValue");
}

@Override
public boolean matches(Document doc) {
Value other = doc.getField(getField());
return other != null && ProtoValues.contains(getValue().getArrayValue(), other);
return other != null && Values.contains(getValue().getArrayValue(), other);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;

/** Filter that matches on key fields (i.e. '__name__'). */
Expand All @@ -28,7 +28,7 @@ public class KeyFieldFilter extends FieldFilter {

KeyFieldFilter(FieldPath field, Operator operator, Value value) {
super(field, operator, value);
hardAssert(ProtoValues.isReferenceValue(value), "KeyFieldFilter expects a ReferenceValue");
hardAssert(Values.isReferenceValue(value), "KeyFieldFilter expects a ReferenceValue");
key = DocumentKey.fromName(getValue().getReferenceValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firestore.v1.Value;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,10 +30,10 @@ public class KeyFieldInFilter extends FieldFilter {
KeyFieldInFilter(FieldPath field, Value value) {
super(field, Operator.IN, value);

hardAssert(ProtoValues.isArray(value), "KeyFieldInFilter expects an ArrayValue");
hardAssert(Values.isArray(value), "KeyFieldInFilter expects an ArrayValue");
for (Value element : value.getArrayValue().getValuesList()) {
hardAssert(
ProtoValues.isReferenceValue(element),
Values.isReferenceValue(element),
"Comparing on key with IN, but an array value was not a ReferenceValue");
keys.add(DocumentKey.fromName(element.getReferenceValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.util.Assert;
import com.google.firestore.v1.Value;

Expand Down Expand Up @@ -66,7 +66,7 @@ int compare(Document d1, Document d2) {
Value v2 = d2.getField(field);
Assert.hardAssert(
v1 != null && v2 != null, "Trying to compare documents on fields that don't exist.");
return direction.getComparisonModifier() * ProtoValues.compare(v1, v2);
return direction.getComparisonModifier() * Values.compare(v1, v2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.annotation.Nullable;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.model.mutation.FieldTransform;
import com.google.firebase.firestore.model.mutation.Mutation;
Expand All @@ -27,7 +28,6 @@
import com.google.firebase.firestore.model.mutation.SetMutation;
import com.google.firebase.firestore.model.mutation.TransformMutation;
import com.google.firebase.firestore.model.mutation.TransformOperation;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firebase.firestore.util.Assert;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.MaybeDocument;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.value.ProtoValues;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.util.Assert;
import com.google.firestore.v1.Value;
import java.util.Arrays;
Expand Down Expand Up @@ -166,7 +166,7 @@ private static double estimateFilterSelectivity(Filter filter) {
hardAssert(filter instanceof FieldFilter, "Filter type expected to be FieldFilter");
FieldFilter fieldFilter = (FieldFilter) filter;
Value filterValue = fieldFilter.getValue();
if (ProtoValues.isNullValue(filterValue) || ProtoValues.isNanValue(filterValue)) {
if (Values.isNullValue(filterValue) || Values.isNanValue(filterValue)) {
return HIGH_SELECTIVITY;
} else {
double operatorSelectivity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.MaybeDocument;
import com.google.firebase.firestore.model.NoDocument;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.UnknownDocument;
import com.google.firebase.firestore.model.mutation.Mutation;
import com.google.firebase.firestore.model.mutation.MutationBatch;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firebase.firestore.remote.RemoteSerializer;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.MaybeDocument;
import com.google.firebase.firestore.model.NoDocument;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.mutation.Mutation;
import com.google.firebase.firestore.model.mutation.MutationBatch;
import com.google.firebase.firestore.model.mutation.MutationBatchResult;
import com.google.firebase.firestore.model.mutation.PatchMutation;
import com.google.firebase.firestore.model.mutation.Precondition;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firebase.firestore.remote.RemoteEvent;
import com.google.firebase.firestore.remote.TargetChange;
import com.google.firebase.firestore.util.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.firebase.firestore.model.value.ObjectValue;
import com.google.firestore.v1.Value;
import java.util.Comparator;

Expand Down
Loading