From 3ccc7ed1660a1cc5eb0853bbdd2a38ba10e996e8 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Mon, 19 Oct 2015 17:01:57 -0700 Subject: [PATCH] Add getters, remove filtering --- .../java/com/google/gcloud/datastore/GeoPoint.java | 13 ++++++++++--- .../java/com/google/gcloud/datastore/GqlQuery.java | 10 ---------- .../google/gcloud/datastore/StructuredQuery.java | 5 ----- .../com/google/gcloud/datastore/BaseEntityTest.java | 2 +- .../com/google/gcloud/datastore/DatastoreTest.java | 3 ++- .../com/google/gcloud/datastore/GeoPointTest.java | 4 ++-- .../google/gcloud/datastore/SerializationTest.java | 2 +- 7 files changed, 16 insertions(+), 23 deletions(-) diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GeoPoint.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GeoPoint.java index 5d7d87ebc121..39dde9a9f85b 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GeoPoint.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GeoPoint.java @@ -46,6 +46,14 @@ public final class GeoPoint extends Serializable { this.longitude = longitude; } + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + @Override public String toString() { return Double.toString(latitude) + ", " + Double.toString(longitude); @@ -58,9 +66,8 @@ public int hashCode() { @Override public boolean equals(Object obj) { - return obj == this - || (obj instanceof GeoPoint && new Double(this.latitude).equals(((GeoPoint) obj).latitude)) - && new Double(this.longitude).equals(((GeoPoint) obj).longitude); + return obj == this || (obj instanceof GeoPoint && this.latitude == ((GeoPoint) obj).latitude + && this.longitude == ((GeoPoint) obj).longitude); } public static GeoPoint of(double latitude, double longitude) { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java index 2205c7c270a3..7fcb562fea89 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java @@ -212,11 +212,6 @@ public Builder setBinding(String name, DateTime... value) { namedBindings.put(name, toBinding(DateTimeValue.MARSHALLER, Arrays.asList(value))); return this; } - - public Builder setBinding(String name, GeoPoint... value) { - namedBindings.put(name, toBinding(GeoPointValue.MARSHALLER, Arrays.asList(value))); - return this; - } public Builder setBinding(String name, Key... value) { namedBindings.put(name, toBinding(KeyValue.MARSHALLER, Arrays.asList(value))); @@ -263,11 +258,6 @@ public Builder addBinding(DateTime... value) { return this; } - public Builder addBinding(GeoPoint... value) { - positionalBindings.add(toBinding(GeoPointValue.MARSHALLER, Arrays.asList(value))); - return this; - } - public Builder addBinding(Key... value) { positionalBindings.add(toBinding(KeyValue.MARSHALLER, Arrays.asList(value))); return this; diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java index 87f92f6d05b4..1b82991cb8c8 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java @@ -21,7 +21,6 @@ import static com.google.gcloud.datastore.BooleanValue.of; import static com.google.gcloud.datastore.DateTimeValue.of; import static com.google.gcloud.datastore.DoubleValue.of; -import static com.google.gcloud.datastore.GeoPointValue.of; import static com.google.gcloud.datastore.KeyValue.of; import static com.google.gcloud.datastore.LongValue.of; import static com.google.gcloud.datastore.StringValue.of; @@ -421,10 +420,6 @@ public static PropertyFilter eq(String property, DateTime value) { return new PropertyFilter(property, Operator.EQUAL, of(value)); } - public static PropertyFilter eq(String property, GeoPoint value) { - return new PropertyFilter(property, Operator.EQUAL, of(value)); - } - public static PropertyFilter eq(String property, Key value) { return new PropertyFilter(property, Operator.EQUAL, of(value)); } diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java index 8053b2d80b1d..5ca68bf848ce 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java @@ -35,7 +35,7 @@ public class BaseEntityTest { private static final Blob BLOB = Blob.copyFrom(new byte[]{1, 2}); private static final DateTime DATE_TIME = DateTime.now(); - private static final GeoPoint GEO_POINT = new GeoPoint(30.5, -40.5); + private static final GeoPoint GEO_POINT = new GeoPoint(37.422035, -122.084124); private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); private static final Entity ENTITY = Entity.builder(KEY).set("name", "foo").build(); private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k1").build(); diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java index 320c4f3d67c8..c890a6b67aa8 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java @@ -74,7 +74,8 @@ public class DatastoreTest { .build(); private static final ListValue LIST_VALUE2 = ListValue.of(Collections.singletonList(KEY_VALUE)); private static final DateTimeValue DATE_TIME_VALUE = new DateTimeValue(DateTime.now()); - private static final GeoPointValue GEO_POINT_VALUE = new GeoPointValue(new GeoPoint(30.5, 40.5)); + private static final GeoPointValue GEO_POINT_VALUE = + new GeoPointValue(new GeoPoint(37.422035, -122.084124)); private static final FullEntity PARTIAL_ENTITY1 = FullEntity.builder(INCOMPLETE_KEY2).set("str", STR_VALUE).set("bool", BOOL_VALUE) .set("list", LIST_VALUE1).build(); diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/GeoPointTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/GeoPointTest.java index 61bcf0fd4f26..2f076d915c15 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/GeoPointTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/GeoPointTest.java @@ -28,8 +28,8 @@ public class GeoPointTest { @Rule public ExpectedException thrown = ExpectedException.none(); - private static GeoPoint gp1 = new GeoPoint(10.5, 20.5); - private static GeoPoint gp2 = new GeoPoint(10.5, 30.5); + private static GeoPoint gp1 = new GeoPoint(37.422035, -122.084124); + private static GeoPoint gp2 = new GeoPoint(0.0, 0.0); private static final String INVALID_LAT_MESSAGE = "latitude must be in the range [-90, 90] degrees"; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java index fe2be0a04b76..b2ee24862688 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java @@ -45,7 +45,7 @@ public class SerializationTest { IncompleteKey.builder(KEY1, "v").ancestors(PathElement.of("p", 1)).build(); private static final Key KEY2 = Key.builder(KEY1, "v", 2).build(); private static final DateTime DATE_TIME1 = DateTime.now(); - private static final GeoPoint GEO_POINT = new GeoPoint(30.5, 40.5); + private static final GeoPoint GEO_POINT = new GeoPoint(37.422035, -122.084124); private static final Blob BLOB1 = Blob.copyFrom(UTF_8.encode("hello world")); private static final Cursor CURSOR1 = Cursor.copyFrom(new byte[] {1,2}); private static final Cursor CURSOR2 = Cursor.copyFrom(new byte[]{10});