Skip to content

Commit 2de0d60

Browse files
committed
---
yaml --- r: 1857 b: refs/heads/pubsub-alpha c: f84a3b1 h: refs/heads/master i: 1855: 5228324
1 parent e8674b8 commit 2de0d60

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

  • branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 79001cf046ca1f33427231655dd457cd41015e09
6+
refs/heads/pubsub-alpha: f84a3b115196ca702d3c4a420870edcbb3f86596
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Field.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.google.gcloud.bigquery;
1818

19+
import static com.google.common.base.MoreObjects.firstNonNull;
1920
import static com.google.common.base.Preconditions.checkArgument;
2021
import static com.google.common.base.Preconditions.checkNotNull;
2122

23+
import com.google.api.client.util.Data;
2224
import com.google.api.services.bigquery.model.TableFieldSchema;
2325
import com.google.common.base.Function;
2426
import com.google.common.base.MoreObjects;
@@ -180,7 +182,7 @@ public boolean equals(Object obj) {
180182
* than one value.
181183
*/
182184
public enum Mode {
183-
NULLABLE, REQUIRED, REPEATED
185+
NULLABLE, REQUIRED, REPEATED, NOT_SET
184186
}
185187

186188
private final String name;
@@ -197,6 +199,13 @@ public static final class Builder {
197199

198200
private Builder() {}
199201

202+
private Builder(Field field) {
203+
this.name = field.name;
204+
this.type = field.type;
205+
this.mode = field.mode;
206+
this.description = field.description;
207+
}
208+
200209
/**
201210
* Sets the field name. The name must contain only letters (a-z, A-Z), numbers (0-9), or
202211
* underscores (_), and must start with a letter or underscore. The maximum length is 128
@@ -222,15 +231,15 @@ public Builder type(Type type) {
222231
* Sets the mode of the field. When not specified {@link Mode#NULLABLE} is used.
223232
*/
224233
public Builder mode(Mode mode) {
225-
this.mode = mode;
234+
this.mode = firstNonNull(mode, Mode.NOT_SET);
226235
return this;
227236
}
228237

229238
/**
230239
* Sets the field description. The maximum length is 16K characters.
231240
*/
232241
public Builder description(String description) {
233-
this.description = description;
242+
this.description = firstNonNull(description, Data.<String>nullOf(String.class));
234243
return this;
235244
}
236245

@@ -270,14 +279,14 @@ public Type type() {
270279
* Returns the field mode. By default {@link Mode#NULLABLE} is used.
271280
*/
272281
public Mode mode() {
273-
return mode;
282+
return mode == Mode.NOT_SET ? null : mode;
274283
}
275284

276285
/**
277286
* Returns the field description.
278287
*/
279288
public String description() {
280-
return description;
289+
return Data.isNull(description) ? null : description;
281290
}
282291

283292
/**
@@ -292,11 +301,7 @@ public List<Field> fields() {
292301
* Returns a builder for the {@code Field} object.
293302
*/
294303
public Builder toBuilder() {
295-
return new Builder()
296-
.name(this.name)
297-
.type(this.type)
298-
.mode(this.mode)
299-
.description(this.description);
304+
return new Builder(this);
300305
}
301306

302307
@Override
@@ -324,7 +329,7 @@ TableFieldSchema toPb() {
324329
fieldSchemaPb.setName(name);
325330
fieldSchemaPb.setType(type.value().name());
326331
if (mode != null) {
327-
fieldSchemaPb.setMode(mode.name());
332+
fieldSchemaPb.setMode(mode == Mode.NOT_SET ? Data.<String>nullOf(String.class) : mode.name());
328333
}
329334
if (description != null) {
330335
fieldSchemaPb.setDescription(description);

0 commit comments

Comments
 (0)