Skip to content

Commit 2c66eaf

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 4717 b: refs/heads/logging-alpha c: f6eeddd h: refs/heads/master i: 4715: bf64988
1 parent fca4e8e commit 2c66eaf

16 files changed

Lines changed: 392 additions & 45 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: 824560744262c447121b852b9f1335cf052084b7
15+
refs/heads/logging-alpha: f6eedddbb5d0f8a297633a524cf0eee08046c53c
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ protected B self() {
122122
}
123123

124124
public B projectId(String projectId) {
125-
this.projectId =
126-
checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default.");
125+
this.projectId = projectId;
127126
return self();
128127
}
129128

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.google.gcloud.datastore.DateTimeValue.of;
2222
import static com.google.gcloud.datastore.DoubleValue.of;
2323
import static com.google.gcloud.datastore.EntityValue.of;
24+
import static com.google.gcloud.datastore.GeoPointValue.of;
2425
import static com.google.gcloud.datastore.KeyValue.of;
2526
import static com.google.gcloud.datastore.ListValue.of;
2627
import static com.google.gcloud.datastore.LongValue.of;
@@ -159,6 +160,11 @@ public B set(String name, DateTime value) {
159160
return self();
160161
}
161162

163+
public B set(String name, GeoPoint value) {
164+
properties.put(name, of(value));
165+
return self();
166+
}
167+
162168
public B set(String name, Key value) {
163169
properties.put(name, of(value));
164170
return self();
@@ -320,6 +326,17 @@ public DateTime getDateTime(String name) {
320326
return ((Value<DateTime>) getValue(name)).get();
321327
}
322328

329+
/**
330+
* Returns the property value as a GeoPoint.
331+
*
332+
* @throws DatastoreException if not such property.
333+
* @throws ClassCastException if value is not a GeoPoint.
334+
*/
335+
@SuppressWarnings("unchecked")
336+
public GeoPoint getGeoPoint(String name) {
337+
return ((Value<GeoPoint>) getValue(name)).get();
338+
}
339+
323340
/**
324341
* Returns the property value as a Key.
325342
*
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.datastore;
18+
19+
import static com.google.common.base.Preconditions.checkArgument;
20+
21+
import com.google.protobuf.InvalidProtocolBufferException;
22+
23+
import java.util.Objects;
24+
25+
/**
26+
* A Google Cloud Datastore GeoPoint (represented by latitude and longitude in degrees).
27+
* This class is immutable.
28+
*
29+
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
30+
* Entities, Properties, and Keys</a>
31+
*/
32+
public final class GeoPoint extends Serializable<com.google.type.LatLng> {
33+
34+
private static final long serialVersionUID = 9077060962655752073L;
35+
36+
private final transient double latitude;
37+
private final transient double longitude;
38+
39+
GeoPoint(double latitude, double longitude) {
40+
checkArgument(
41+
latitude >= -90.0 && latitude <= 90.0, "latitude must be in the range [-90, 90] degrees");
42+
checkArgument(
43+
longitude >= -180.0 && longitude <= 180.0,
44+
"latitude must be in the range [-180, 180] degrees");
45+
this.latitude = latitude;
46+
this.longitude = longitude;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return Double.toString(latitude) + ", " + Double.toString(longitude);
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
return Objects.hash(latitude, longitude);
57+
}
58+
59+
@Override
60+
public boolean equals(Object obj) {
61+
return obj == this
62+
|| (obj instanceof GeoPoint && new Double(this.latitude).equals(((GeoPoint) obj).latitude))
63+
&& new Double(this.longitude).equals(((GeoPoint) obj).longitude);
64+
}
65+
66+
public static GeoPoint of(double latitude, double longitude) {
67+
return new GeoPoint(latitude, longitude);
68+
}
69+
70+
@Override
71+
protected com.google.type.LatLng toPb() {
72+
return com.google.type.LatLng.newBuilder()
73+
.setLatitude(latitude)
74+
.setLongitude(longitude)
75+
.build();
76+
}
77+
78+
@Override
79+
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
80+
com.google.type.LatLng parsedLatLng = com.google.type.LatLng.parseFrom(bytesPb);
81+
return new GeoPoint(parsedLatLng.getLatitude(), parsedLatLng.getLongitude());
82+
}
83+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.datastore;
18+
19+
import static com.google.datastore.v1beta3.Value.GEO_POINT_VALUE_FIELD_NUMBER;
20+
21+
public final class GeoPointValue extends Value<GeoPoint> {
22+
23+
private static final long serialVersionUID = -5810614280642405898L;
24+
25+
static final BaseMarshaller<GeoPoint, GeoPointValue, Builder> MARSHALLER =
26+
new BaseMarshaller<GeoPoint, GeoPointValue, Builder>() {
27+
28+
private static final long serialVersionUID = -3550567536035178649L;
29+
30+
@Override
31+
public int getProtoFieldId() {
32+
return GEO_POINT_VALUE_FIELD_NUMBER;
33+
}
34+
35+
@Override
36+
public Builder newBuilder(GeoPoint value) {
37+
return builder(value);
38+
}
39+
40+
@Override
41+
protected GeoPoint getValue(com.google.datastore.v1beta3.Value from) {
42+
return new GeoPoint(
43+
from.getGeoPointValue().getLatitude(), from.getGeoPointValue().getLongitude());
44+
}
45+
46+
@Override
47+
protected void setValue(GeoPointValue from, com.google.datastore.v1beta3.Value.Builder to) {
48+
to.setGeoPointValue(from.get().toPb());
49+
}
50+
};
51+
52+
public static final class Builder extends Value.BaseBuilder<GeoPoint, GeoPointValue, Builder> {
53+
54+
private Builder() {
55+
super(ValueType.GEO_POINT);
56+
}
57+
58+
@Override
59+
public GeoPointValue build() {
60+
return new GeoPointValue(this);
61+
}
62+
}
63+
64+
public GeoPointValue(GeoPoint value) {
65+
this(builder(value));
66+
}
67+
68+
private GeoPointValue(Builder builder) {
69+
super(builder);
70+
}
71+
72+
@Override
73+
public Builder toBuilder() {
74+
return new Builder().mergeFrom(this);
75+
}
76+
77+
public static GeoPointValue of(GeoPoint value) {
78+
return new GeoPointValue(value);
79+
}
80+
81+
public static Builder builder(GeoPoint value) {
82+
return new Builder().set(value);
83+
}
84+
}

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ public Builder<V> setBinding(String name, DateTime... value) {
212212
namedBindings.put(name, toBinding(DateTimeValue.MARSHALLER, Arrays.asList(value)));
213213
return this;
214214
}
215+
216+
public Builder<V> setBinding(String name, GeoPoint... value) {
217+
namedBindings.put(name, toBinding(GeoPointValue.MARSHALLER, Arrays.asList(value)));
218+
return this;
219+
}
215220

216221
public Builder<V> setBinding(String name, Key... value) {
217222
namedBindings.put(name, toBinding(KeyValue.MARSHALLER, Arrays.asList(value)));
@@ -258,6 +263,11 @@ public Builder<V> addBinding(DateTime... value) {
258263
return this;
259264
}
260265

266+
public Builder<V> addBinding(GeoPoint... value) {
267+
positionalBindings.add(toBinding(GeoPointValue.MARSHALLER, Arrays.asList(value)));
268+
return this;
269+
}
270+
261271
public Builder<V> addBinding(Key... value) {
262272
positionalBindings.add(toBinding(KeyValue.MARSHALLER, Arrays.asList(value)));
263273
return this;

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.gcloud.datastore;
1818

19+
import com.google.common.base.MoreObjects;
1920
import com.google.common.collect.ImmutableList;
2021

2122
/**
@@ -28,14 +29,14 @@ public final class KeyFactory extends BaseKey.Builder<KeyFactory> {
2829
private final String ns;
2930

3031
public KeyFactory(String projectId) {
31-
this(projectId, "");
32+
this(projectId, null);
3233
}
3334

3435
public KeyFactory(String projectId, String namespace) {
3536
super(projectId);
3637
namespace(namespace);
3738
this.pi = projectId;
38-
this.ns = namespace;
39+
this.ns = MoreObjects.firstNonNull(namespace, "");
3940
}
4041

4142
public IncompleteKey newKey() {

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.google.gcloud.datastore.BooleanValue.of;
2222
import static com.google.gcloud.datastore.DateTimeValue.of;
2323
import static com.google.gcloud.datastore.DoubleValue.of;
24+
import static com.google.gcloud.datastore.GeoPointValue.of;
2425
import static com.google.gcloud.datastore.KeyValue.of;
2526
import static com.google.gcloud.datastore.LongValue.of;
2627
import static com.google.gcloud.datastore.StringValue.of;
@@ -420,6 +421,10 @@ public static PropertyFilter eq(String property, DateTime value) {
420421
return new PropertyFilter(property, Operator.EQUAL, of(value));
421422
}
422423

424+
public static PropertyFilter eq(String property, GeoPoint value) {
425+
return new PropertyFilter(property, Operator.EQUAL, of(value));
426+
}
427+
423428
public static PropertyFilter eq(String property, Key value) {
424429
return new PropertyFilter(property, Operator.EQUAL, of(value));
425430
}

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Validator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ static String validateDatabase(String projectId) {
4545
}
4646

4747
static String validateNamespace(String namespace) {
48-
checkArgument(namespace != null, "Namespace cannot be null. Leave unset for default.");
48+
if (Strings.isNullOrEmpty(namespace)) {
49+
return "";
50+
}
4951
checkArgument(namespace.length() <= MAX_NAMESPACE_LENGTH,
5052
"namespace must not contain more than 100 characters");
5153
checkArgument(NAMESPACE_PATTERN.matcher(namespace).matches(),

branches/logging-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public enum ValueType {
7878
/**
7979
* Represents a raw/unparsed value.
8080
*/
81-
RAW_VALUE(RawValue.MARSHALLER);
81+
RAW_VALUE(RawValue.MARSHALLER),
8282

8383
/**
84-
* TODO(ajaykannan): add GEO_POINT_VALUE
85-
* Will represent a geolocation value in latitude/longitude
84+
* Represents a {@link GeoPoint} value
8685
*/
86+
GEO_POINT(GeoPointValue.MARSHALLER);
8787

8888
private static final ImmutableMap<Integer, ValueType> DESCRIPTOR_TO_TYPE_MAP;
8989

0 commit comments

Comments
 (0)