Search in sources :

Example 6 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project firebase-android-sdk by firebase.

the class QueryTest method testCanonicalIdsAreStable.

@Test
public void testCanonicalIdsAreStable() {
    // This test aims to ensure that we do not break canonical IDs, as they are used as keys in
    // the TargetCache.
    Query baseQuery = Query.atPath(ResourcePath.fromString("collection"));
    assertCanonicalId(baseQuery, "collection|f:|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", ">", "a")), "collection|f:a>a|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "<=", new GeoPoint(90.0, -90.0))), "collection|f:a<=geo(90.0,-90.0)|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "<=", new Timestamp(60, 3000))), "collection|f:a<=time(60,3000)|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", ">=", Blob.fromBytes(new byte[] { 1, 2, 3 }))), "collection|f:a>=010203|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", Arrays.asList(1, 2, 3))), "collection|f:a==[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "!=", Arrays.asList(1, 2, 3))), "collection|f:a!=[1,2,3]|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", Double.NaN)), "collection|f:a==NaN|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("__name__", "==", ref("collection/id"))), "collection|f:__name__==collection/id|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "==", map("a", "b", "inner", map("d", "c")))), "collection|f:a=={a:b,inner:{d:c}}|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "in", Arrays.asList(1, 2, 3))), "collection|f:ain[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "not-in", Arrays.asList(1, 2, 3))), "collection|f:anot_in[1,2,3]|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "array-contains-any", Arrays.asList(1, 2, 3))), "collection|f:aarray_contains_any[1,2,3]|ob:__name__asc");
    assertCanonicalId(baseQuery.filter(filter("a", "array-contains", "a")), "collection|f:aarray_containsa|ob:__name__asc");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")), "collection|f:|ob:aasc__name__asc");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")).startAt(bound(/* inclusive= */
    true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|lb:b:foo,[1,2,3]");
    assertCanonicalId(baseQuery.orderBy(orderBy("a")).endAt(bound(/* inclusive= */
    true, "foo", Arrays.asList(1, 2, 3))), "collection|f:|ob:aasc__name__asc|ub:a:foo,[1,2,3]");
    assertCanonicalId(baseQuery.limitToFirst(5), "collection|f:|ob:__name__asc|l:5");
    assertCanonicalId(baseQuery.limitToLast(5), "collection|f:|ob:__name__desc|l:5");
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 7 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project firebase-android-sdk by firebase.

the class CustomClassMapper method serialize.

@SuppressWarnings("unchecked")
private static <T> Object serialize(T o, ErrorPath path) {
    if (path.getLength() > MAX_DEPTH) {
        throw serializeError(path, "Exceeded maximum depth of " + MAX_DEPTH + ", which likely indicates there's an object cycle");
    }
    if (o == null) {
        return null;
    } else if (o instanceof Number) {
        if (o instanceof Long || o instanceof Integer || o instanceof Double || o instanceof Float) {
            return o;
        } else {
            throw serializeError(path, String.format("Numbers of type %s are not supported, please use an int, long, float or double", o.getClass().getSimpleName()));
        }
    } else if (o instanceof String) {
        return o;
    } else if (o instanceof Boolean) {
        return o;
    } else if (o instanceof Character) {
        throw serializeError(path, "Characters are not supported, please use Strings");
    } else if (o instanceof Map) {
        Map<String, Object> result = new HashMap<>();
        for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) o).entrySet()) {
            Object key = entry.getKey();
            if (key instanceof String) {
                String keyString = (String) key;
                result.put(keyString, serialize(entry.getValue(), path.child(keyString)));
            } else {
                throw serializeError(path, "Maps with non-string keys are not supported");
            }
        }
        return result;
    } else if (o instanceof Collection) {
        if (o instanceof List) {
            List<Object> list = (List<Object>) o;
            List<Object> result = new ArrayList<>(list.size());
            for (int i = 0; i < list.size(); i++) {
                result.add(serialize(list.get(i), path.child("[" + i + "]")));
            }
            return result;
        } else {
            throw serializeError(path, "Serializing Collections is not supported, please use Lists instead");
        }
    } else if (o.getClass().isArray()) {
        throw serializeError(path, "Serializing Arrays is not supported, please use Lists instead");
    } else if (o instanceof Enum) {
        String enumName = ((Enum<?>) o).name();
        try {
            Field enumField = o.getClass().getField(enumName);
            return BeanMapper.propertyName(enumField);
        } catch (NoSuchFieldException ex) {
            return enumName;
        }
    } else if (o instanceof Date || o instanceof Timestamp || o instanceof GeoPoint || o instanceof Blob || o instanceof DocumentReference || o instanceof FieldValue) {
        return o;
    } else if (o instanceof Uri || o instanceof URI || o instanceof URL) {
        return o.toString();
    } else {
        Class<T> clazz = (Class<T>) o.getClass();
        BeanMapper<T> mapper = loadOrCreateBeanMapperForClass(clazz);
        return mapper.serialize(o, path);
    }
}
Also used : ArrayList(java.util.ArrayList) ServerTimestamp(com.google.firebase.firestore.ServerTimestamp) Timestamp(com.google.firebase.Timestamp) Uri(android.net.Uri) URI(java.net.URI) URL(java.net.URL) Field(java.lang.reflect.Field) GeoPoint(com.google.firebase.firestore.GeoPoint) ArrayList(java.util.ArrayList) List(java.util.List) FieldValue(com.google.firebase.firestore.FieldValue) DocumentReference(com.google.firebase.firestore.DocumentReference) Blob(com.google.firebase.firestore.Blob) GeoPoint(com.google.firebase.firestore.GeoPoint) Date(java.util.Date) Collection(java.util.Collection) AccessibleObject(java.lang.reflect.AccessibleObject) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesGeoPoints.

@Test
public void testEncodesGeoPoints() {
    Value geoPoint = wrap(new GeoPoint(1.23, 4.56));
    Value.Builder proto = Value.newBuilder();
    proto.setGeoPointValue(LatLng.newBuilder().setLatitude(1.23).setLongitude(4.56));
    assertRoundTrip(geoPoint, proto.build(), Value.ValueTypeCase.GEO_POINT_VALUE);
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) ObjectValue(com.google.firebase.firestore.model.ObjectValue) Values.refValue(com.google.firebase.firestore.model.Values.refValue) NullValue(com.google.protobuf.NullValue) ServerValue(com.google.firestore.v1.DocumentTransform.FieldTransform.ServerValue) Value(com.google.firestore.v1.Value) Int32Value(com.google.protobuf.Int32Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 9 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project turtleparties by CMPUT301W22T21.

the class ScanQRActivity method setLocation.

public void setLocation() {
    if (scannedQR != null) {
        Log.d("GEOERR", latitude + "   " + longitude);
        GeoPoint newGP = new GeoPoint((latitude), (longitude));
        scannedQR.setGeolocation(newGP);
    }
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint)

Aggregations

GeoPoint (com.google.firebase.firestore.GeoPoint)9 Test (org.junit.Test)6 Timestamp (com.google.firebase.Timestamp)4 Uri (android.net.Uri)1 NonNull (androidx.annotation.NonNull)1 LatLng (com.google.android.gms.maps.model.LatLng)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)1 Task (com.google.android.gms.tasks.Task)1 EqualsTester (com.google.common.testing.EqualsTester)1 Blob (com.google.firebase.firestore.Blob)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)1 FieldValue (com.google.firebase.firestore.FieldValue)1 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 ServerTimestamp (com.google.firebase.firestore.ServerTimestamp)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 Values.refValue (com.google.firebase.firestore.model.Values.refValue)1