Skip to content

Commit 68755b5

Browse files
committed
---
yaml --- r: 41 b: refs/heads/master c: 5f0c319 h: refs/heads/master i: 39: 8f0624d v: v3
1 parent 984fdce commit 68755b5

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f6d541a3802de5ffe3aa4a56e30d3de8ed799476
2+
refs/heads/master: 5f0c3199bde799151c89e132ba11982bf2aaa904

trunk/src/main/java/com/google/gcloud/datastore/Key.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* A key that is guaranteed to be complete and could be used to reference a
1616
* Google Cloud Datastore {@link Entity}.
17-
* This class is immutable. To edit (a copy) use {@link #builder()}.
17+
* This class is immutable.
1818
*
1919
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore Entities, Properties, and Keys</a>
2020
*/
@@ -47,6 +47,15 @@ public Builder(Key parent, String kind, long id) {
4747
this.id = id;
4848
}
4949

50+
public Builder(Key from) {
51+
super(from);
52+
if (from.hasId()) {
53+
id = from.id();
54+
} else {
55+
name = from.name();
56+
}
57+
}
58+
5059
@Override
5160
public Builder addAncestor(String kind, long id) {
5261
super.addAncestor(kind, id);
@@ -122,13 +131,6 @@ private Key(PartialKey key, long id) {
122131
super(key.dataset(), key.namespace(), newPath(key, id));
123132
}
124133

125-
@Override
126-
public Builder builder() {
127-
Builder builder =
128-
hasId() ? new Builder(dataset(), kind(), id()) : new Builder(dataset(), kind(), name());
129-
return builder.namespace(namespace()).addAncestors(ancestors());
130-
}
131-
132134
public boolean hasId() {
133135
return id() != null;
134136
}

trunk/src/main/java/com/google/gcloud/datastore/PartialKey.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* A partial key (without a name or id).
2020
* Could be used as metadata for {@link PartialEntity}.
21-
* This class is immutable. To edit (a copy) use {@link #builder()}.
21+
* This class is immutable.
2222
*/
2323
public class PartialKey extends Serializable<DatastoreV1.Key> {
2424

@@ -142,6 +142,13 @@ public Builder(Key parent, String kind) {
142142
this.kind = kind;
143143
}
144144

145+
public Builder(PartialKey from) {
146+
dataset = from.dataset();
147+
namespace = from.namespace();
148+
kind = from.kind();
149+
ancestors.addAll(from.ancestors());
150+
}
151+
145152
public Builder addAncestor(String kind, long id) {
146153
checkArgument(id != 0, "id must not be equal to zero");
147154
return addAncestor(new Ancestor(kind, id));
@@ -238,10 +245,6 @@ public String kind() {
238245
return getLeaf().kind();
239246
}
240247

241-
public Builder builder() {
242-
return new Builder(dataset(), kind()).namespace(namespace()).addAncestors(ancestors());
243-
}
244-
245248
public Key newKey(String name) {
246249
return new Key.Builder(dataset(), kind(), name)
247250
.namespace(namespace())

0 commit comments

Comments
 (0)