Skip to content

Commit 5f0c319

Browse files
committed
2 parents e9f8f49 + f6d541a commit 5f0c319

12 files changed

Lines changed: 145 additions & 213 deletions

File tree

.classpath

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,5 @@
2323
</attributes>
2424
</classpathentry>
2525
<classpathentry kind="var" path="ECLIPSE_HOME"/>
26-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
27-
<attributes>
28-
<attribute name="maven.pomderived" value="true"/>
29-
</attributes>
30-
</classpathentry>
31-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
32-
<attributes>
33-
<attribute name="maven.pomderived" value="true"/>
34-
</attributes>
35-
</classpathentry>
3626
<classpathentry kind="output" path="target/classes"/>
3727
</classpath>

src/main/java/com/google/gcloud/datastore/DateAndTimeValue.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/main/java/com/google/gcloud/datastore/DateAndTime.java renamed to src/main/java/com/google/gcloud/datastore/DateTime.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
import java.util.Date;
99

1010
/**
11-
* A Google Cloud Datastore timestamp.
12-
* A Datastore timestamp is represented in micro-seconds.
11+
* A Google Cloud Datastore timestamp (represented in micro-seconds).
1312
* This class is immutable.
1413
*
1514
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore Entities, Properties, and Keys</a>
1615
*/
17-
public final class DateAndTime implements java.io.Serializable {
16+
public final class DateTime implements java.io.Serializable {
1817

1918
private static final long serialVersionUID = 7343324797621228378L;
2019

2120
private final long timestampMicroseconds;
2221

23-
DateAndTime(long timestampMicroseconds) {
22+
DateTime(long timestampMicroseconds) {
2423
this.timestampMicroseconds = timestampMicroseconds;
2524
}
2625

@@ -36,10 +35,10 @@ public int hashCode() {
3635

3736
@Override
3837
public boolean equals(Object obj) {
39-
if (!(obj instanceof DateAndTime)) {
38+
if (!(obj instanceof DateTime)) {
4039
return false;
4140
}
42-
return timestampMicroseconds == ((DateAndTime) obj).timestampMicroseconds;
41+
return timestampMicroseconds == ((DateTime) obj).timestampMicroseconds;
4342
}
4443

4544
public long timestampMicroseconds() {
@@ -60,15 +59,15 @@ public Calendar toCalendar() {
6059
return cal;
6160
}
6261

63-
public static DateAndTime now() {
64-
return new DateAndTime(System.nanoTime() / 1000L);
62+
public static DateTime now() {
63+
return new DateTime(System.nanoTime() / 1000L);
6564
}
6665

67-
public static DateAndTime copyFrom(Date date) {
68-
return new DateAndTime(checkNotNull(date).getTime() * 1000L);
66+
public static DateTime copyFrom(Date date) {
67+
return new DateTime(checkNotNull(date).getTime() * 1000L);
6968
}
7069

71-
public static DateAndTime copyFrom(Calendar calendar) {
70+
public static DateTime copyFrom(Calendar calendar) {
7271
return copyFrom(calendar.getTime());
7372
}
7473
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.google.gcloud.datastore;
2+
3+
import static com.google.api.services.datastore.DatastoreV1.Value.TIMESTAMP_MICROSECONDS_VALUE_FIELD_NUMBER;
4+
5+
import com.google.api.services.datastore.DatastoreV1;
6+
7+
public final class DateTimeValue
8+
extends Value<DateTime, DateTimeValue, DateTimeValue.Builder> {
9+
10+
private static final long serialVersionUID = -5096238337676649540L;
11+
12+
static final BaseMarshaller<DateTime, DateTimeValue, Builder> MARSHALLER =
13+
new BaseMarshaller<DateTime, DateTimeValue, Builder>() {
14+
15+
@Override
16+
public int getProtoFieldId() {
17+
return TIMESTAMP_MICROSECONDS_VALUE_FIELD_NUMBER;
18+
}
19+
20+
@Override
21+
public Builder newBuilder(DateTime value) {
22+
return new Builder(value);
23+
}
24+
25+
@Override
26+
protected DateTime getValue(DatastoreV1.Value from) {
27+
return new DateTime(from.getTimestampMicrosecondsValue());
28+
}
29+
30+
@Override
31+
protected void setValue(DateTimeValue from, DatastoreV1.Value.Builder to) {
32+
to.setTimestampMicrosecondsValue(from.get().timestampMicroseconds());
33+
}
34+
};
35+
36+
public static final class Builder
37+
extends Value.BaseBuilder<DateTime, DateTimeValue, Builder> {
38+
39+
public Builder(DateTime dateTime) {
40+
super(Type.DATE_TIME);
41+
set(dateTime);
42+
}
43+
44+
@Override
45+
public DateTimeValue build() {
46+
return new DateTimeValue(this);
47+
}
48+
}
49+
50+
public DateTimeValue(DateTime dateTime) {
51+
this(new Builder(dateTime));
52+
}
53+
54+
DateTimeValue(Builder builder) {
55+
super(builder);
56+
}
57+
}

src/main/java/com/google/gcloud/datastore/Entity.java

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.google.gcloud.datastore;
22

3+
import static com.google.common.base.Preconditions.checkNotNull;
4+
35
import com.google.api.services.datastore.DatastoreV1;
46
import com.google.common.base.Preconditions;
57
import com.google.common.collect.ImmutableSortedMap;
@@ -10,53 +12,43 @@
1012
* An entity holds one or more properties, represented by a name (as {@link String})
1113
* and a value (as {@link Value}), and is associated with a {@link Key}.
1214
* For a list of possible values see {@link Value.Type}.
13-
* This class is immutable. To edit (a copy) use {@link #builder()}.
15+
* This class is immutable.
1416
*
1517
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore Entities, Properties, and Keys</a>
1618
*/
1719
public final class Entity extends PartialEntity {
1820

1921
private static final long serialVersionUID = 432961565733066915L;
2022

21-
public static final class Builder extends PartialEntity.Builder {
23+
public static final class Builder extends PropertyContainer.Builder<Entity, Builder> {
24+
25+
private Key key;
2226

2327
public Builder(Key key) {
24-
super(key);
28+
this.key = checkNotNull(key);
2529
}
2630

2731
public Builder(Entity entity) {
2832
super(entity);
33+
key = entity.key();
2934
}
3035

3136
/**
3237
* Create a Builder for the given key and with the properties from the given entity.
3338
*/
3439
public Builder(Key key, PartialEntity entity) {
35-
super(key, entity);
36-
}
37-
38-
@Override
39-
public Builder clearProperties() {
40-
super.clearProperties();
41-
return this;
42-
}
43-
44-
@Override
45-
public Builder removeProperty(String name) {
46-
super.removeProperty(name);
47-
return this;
40+
super(entity);
41+
this.key = key;
4842
}
4943

50-
@Override
51-
public Builder setProperty(String name, Value<?, ?, ?> value) {
52-
super.setProperty(name, value);
44+
public Builder key(Key key) {
45+
this.key = checkNotNull(key);
5346
return this;
5447
}
5548

5649
@Override
57-
public Entity build() {
58-
PartialEntity entity = super.build();
59-
return new Entity((Key) entity.key(), entity.properties());
50+
protected Entity build(ImmutableSortedMap<String, Value<?, ?, ?>> properties) {
51+
return new Entity(key, properties);
6052
}
6153
}
6254

@@ -72,11 +64,6 @@ public Key key() {
7264
return (Key) super.key();
7365
}
7466

75-
@Override
76-
public Builder builder() {
77-
return new Builder(this);
78-
}
79-
8067
@Override
8168
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
8269
return fromPb(DatastoreV1.Entity.parseFrom(bytesPb));

src/main/java/com/google/gcloud/datastore/ListValue.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
import java.util.List;
1111

1212
public final class ListValue extends
13-
Value<List<Value<?, ?, ?>>, ListValue, ListValue.Builder> {
13+
Value<List<? extends Value<?, ?, ?>>, ListValue, ListValue.Builder> {
1414

1515
private static final long serialVersionUID = -5461475706792576395L;
1616

17-
static final BaseMarshaller<List<Value<?, ?, ?>>, ListValue, Builder> MARSHALLER =
18-
new BaseMarshaller<List<Value<?, ?, ?>>, ListValue, Builder>() {
17+
static final BaseMarshaller<List<? extends Value<?, ?, ?>>, ListValue, Builder> MARSHALLER =
18+
new BaseMarshaller<List<? extends Value<?, ?, ?>>, ListValue, Builder>() {
1919

2020
@Override
2121
public int getProtoFieldId() {
2222
return LIST_VALUE_FIELD_NUMBER;
2323
}
2424

2525
@Override
26-
public Builder newBuilder(List<Value<?, ?, ?>> values) {
26+
public Builder newBuilder(List<? extends Value<?, ?, ?>> values) {
2727
return new Builder().set(values);
2828
}
2929

@@ -45,7 +45,7 @@ protected void setValue(ListValue from, DatastoreV1.Value.Builder to) {
4545
};
4646

4747
public static final class Builder extends
48-
Value.BaseBuilder<List<Value<?, ?, ?>>, ListValue, Builder> {
48+
Value.BaseBuilder<List<? extends Value<?, ?, ?>>, ListValue, Builder> {
4949

5050
private ImmutableList.Builder<Value<?, ?, ?>> listBuilder = ImmutableList.builder();
5151

@@ -74,7 +74,7 @@ public Builder addValue(Value<?, ?, ?> first, Value<?, ?, ?>... other) {
7474
* @see com.google.gcloud.datastore.Value.BaseBuilder#set(java.lang.Object)
7575
*/
7676
@Override
77-
public Builder set(List<Value<?, ?, ?>> properties) {
77+
public Builder set(List<? extends Value<?, ?, ?>> properties) {
7878
listBuilder = ImmutableList.<Value<?, ?, ?>>builder();
7979
for (Value<?, ?, ?> property : properties) {
8080
addValue(property);
@@ -83,7 +83,7 @@ public Builder set(List<Value<?, ?, ?>> properties) {
8383
}
8484

8585
@Override
86-
public List<Value<?, ?, ?>> get() {
86+
public List<? extends Value<?, ?, ?>> get() {
8787
return listBuilder.build();
8888
}
8989

@@ -94,7 +94,7 @@ public ListValue build() {
9494
}
9595
}
9696

97-
public ListValue(List<Value<?, ?, ?>> properties) {
97+
public ListValue(List<? extends Value<?, ?, ?>> properties) {
9898
this(new Builder().set(properties));
9999
}
100100

0 commit comments

Comments
 (0)