Skip to content

Commit c394656

Browse files
committed
Merge remote-tracking branch and fix conflict
2 parents 110ab8e + c081812 commit c394656

File tree

13 files changed

+549
-70
lines changed

13 files changed

+549
-70
lines changed

src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public AuthCredentials authCredentials() {
283283
}
284284

285285
public RetryParams retryParams() {
286-
return retryParams;
286+
return retryParams != null ? retryParams : RetryParams.noRetries();
287287
}
288288

289289
public ServiceRpcFactory<R, O> serviceRpcFactory() {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class DatastoreServiceOptions extends ServiceOptions<DatastoreRpc, Datast
4444
private final String namespace;
4545
private final boolean force;
4646
private final boolean normalizeDataset;
47+
private transient DatastoreRpc datastoreRpc;
4748

4849
public static class Builder extends
4950
ServiceOptions.Builder<DatastoreRpc, DatastoreServiceOptions, Builder> {
@@ -178,10 +179,15 @@ public boolean equals(Object obj) {
178179
}
179180

180181
DatastoreRpc datastoreRpc() {
182+
if (datastoreRpc != null) {
183+
return datastoreRpc;
184+
}
181185
if (serviceRpcFactory() != null) {
182-
return serviceRpcFactory().create(this);
186+
datastoreRpc = serviceRpcFactory().create(this);
187+
} else {
188+
datastoreRpc = ServiceRpcProvider.datastore(this);
183189
}
184-
return ServiceRpcProvider.datastore(this);
190+
return datastoreRpc;
185191
}
186192

187193
public static DatastoreServiceOptions defaultInstance() {

src/main/java/com/google/gcloud/storage/BatchRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ public boolean equals(Object obj) {
9696
&& Objects.equals(toGet, other.toGet);
9797
}
9898

99-
Map<Blob, Iterable<BlobSourceOption>> toDelete() {
99+
public Map<Blob, Iterable<BlobSourceOption>> toDelete() {
100100
return toDelete;
101101
}
102102

103-
Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
103+
public Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
104104
return toUpdate;
105105
}
106106

107-
Map<Blob, Iterable<BlobSourceOption>> toGet() {
107+
public Map<Blob, Iterable<BlobSourceOption>> toGet() {
108108
return toGet;
109109
}
110110

src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public static class Result<T extends Serializable> implements Serializable {
4343
private final StorageServiceException exception;
4444

4545

46-
Result(T value) {
46+
public Result(T value) {
4747
this.value = value;
4848
this.exception = null;
4949
}
5050

51-
Result(StorageServiceException exception) {
51+
public Result(StorageServiceException exception) {
5252
this.exception = exception;
5353
this.value = null;
5454
}
@@ -112,7 +112,7 @@ static <T extends Serializable> Result<T> empty() {
112112
}
113113
}
114114

115-
BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
115+
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
116116
List<Result<Blob>> getResult) {
117117
this.deleteResult = ImmutableList.copyOf(deleteResult);
118118
this.updateResult = ImmutableList.copyOf(updateResult);

src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ public Type type() {
103103
return type;
104104
}
105105

106+
@Override
107+
public int hashCode() {
108+
return Objects.hash(type);
109+
}
110+
111+
@Override
112+
public boolean equals(Object obj) {
113+
if (this == obj) {
114+
return true;
115+
}
116+
if (obj == null || getClass() != obj.getClass()) {
117+
return false;
118+
}
119+
final DeleteRule other = (DeleteRule) obj;
120+
return Objects.equals(toPb(), other.toPb());
121+
}
122+
106123
Rule toPb() {
107124
Rule rule = new Rule();
108125
rule.setAction(new Rule.Action().setType(SUPPORTED_ACTION));
@@ -114,7 +131,7 @@ Rule toPb() {
114131

115132
abstract void populateCondition(Rule.Condition condition);
116133

117-
private static DeleteRule fromPb(Rule rule) {
134+
static DeleteRule fromPb(Rule rule) {
118135
if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) {
119136
Rule.Condition condition = rule.getCondition();
120137
Integer age = condition.getAge();
@@ -346,6 +363,23 @@ public static Location of(String value) {
346363
return option == null ? new Location(value) : option.location;
347364
}
348365

366+
@Override
367+
public int hashCode() {
368+
return Objects.hash(value);
369+
}
370+
371+
@Override
372+
public boolean equals(Object obj) {
373+
if (this == obj) {
374+
return true;
375+
}
376+
if (obj == null || getClass() != obj.getClass()) {
377+
return false;
378+
}
379+
final Location other = (Location) obj;
380+
return Objects.equals(this.value, other.value);
381+
}
382+
349383
@Override
350384
public String toString() {
351385
return value();
@@ -412,7 +446,7 @@ public Builder notFoundPage(String notFoundPage) {
412446
return this;
413447
}
414448

415-
public Builder deleteRules(Iterable<DeleteRule> rules) {
449+
public Builder deleteRules(Iterable<? extends DeleteRule> rules) {
416450
this.deleteRules = ImmutableList.copyOf(rules);
417451
return this;
418452
}
@@ -490,7 +524,7 @@ public String name() {
490524
return name;
491525
}
492526

493-
public Entity Owner() {
527+
public Entity owner() {
494528
return owner;
495529
}
496530

@@ -510,7 +544,7 @@ public String notFoundPage() {
510544
return notFoundPage;
511545
}
512546

513-
public List<DeleteRule> deleteRules() {
547+
public List<? extends DeleteRule> deleteRules() {
514548
return deleteRules;
515549
}
516550

@@ -652,6 +686,7 @@ public Rule apply(DeleteRule deleteRule) {
652686
return deleteRule.toPb();
653687
}
654688
}));
689+
bucketPb.setLifecycle(lifecycle);
655690
}
656691
return bucketPb;
657692
}

src/main/java/com/google/gcloud/storage/Cors.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ public Builder maxAgeSeconds(Integer maxAgeSeconds) {
130130
}
131131

132132
public Builder methods(Iterable<Method> methods) {
133-
this.methods = ImmutableList.copyOf(methods);
133+
this.methods = methods != null ? ImmutableList.copyOf(methods) : null;
134134
return this;
135135
}
136136

137137
public Builder origins(Iterable<Origin> origins) {
138-
this.origins = ImmutableList.copyOf(origins);
138+
this.origins = origins != null ? ImmutableList.copyOf(origins) : null;
139139
return this;
140140
}
141141

142142
public Builder responseHeaders(Iterable<String> headers) {
143-
this.responseHeaders = ImmutableList.copyOf(headers);
143+
this.responseHeaders = headers != null ? ImmutableList.copyOf(headers) : null;
144144
return this;
145145
}
146146

@@ -205,25 +205,33 @@ Bucket.Cors toPb() {
205205
Bucket.Cors pb = new Bucket.Cors();
206206
pb.setMaxAgeSeconds(maxAgeSeconds);
207207
pb.setResponseHeader(responseHeaders);
208-
pb.setMethod(newArrayList(transform(methods(), Functions.toStringFunction())));
209-
pb.setOrigin(newArrayList(transform(origins(), Functions.toStringFunction())));
208+
if (methods != null) {
209+
pb.setMethod(newArrayList(transform(methods, Functions.toStringFunction())));
210+
}
211+
if (origins != null) {
212+
pb.setOrigin(newArrayList(transform(origins, Functions.toStringFunction())));
213+
}
210214
return pb;
211215
}
212216

213217
static Cors fromPb(Bucket.Cors cors) {
214218
Builder builder = builder().maxAgeSeconds(cors.getMaxAgeSeconds());
215-
builder.methods(transform(cors.getMethod(), new Function<String, Method>() {
216-
@Override
217-
public Method apply(String name) {
218-
return Method.valueOf(name.toUpperCase());
219-
}
220-
}));
221-
builder.origins(transform(cors.getOrigin(), new Function<String, Origin>() {
222-
@Override
223-
public Origin apply(String value) {
224-
return Origin.of(value);
225-
}
226-
}));
219+
if (cors.getMethod() != null) {
220+
builder.methods(transform(cors.getMethod(), new Function<String, Method>() {
221+
@Override
222+
public Method apply(String name) {
223+
return Method.valueOf(name.toUpperCase());
224+
}
225+
}));
226+
}
227+
if (cors.getOrigin() != null) {
228+
builder.origins(transform(cors.getOrigin(), new Function<String, Origin>() {
229+
@Override
230+
public Origin apply(String value) {
231+
return Origin.of(value);
232+
}
233+
}));
234+
}
227235
builder.responseHeaders(cors.getResponseHeader());
228236
return builder.build();
229237
}

src/main/java/com/google/gcloud/storage/ListResult.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,35 @@ public final class ListResult<T extends Serializable> implements Iterable<T>, Se
3131

3232
private final String cursor;
3333
private final Iterable<T> results;
34+
private final NextPageFetcher<T> pageFetcher;
3435

35-
ListResult(String cursor, Iterable<T> results) {
36+
interface NextPageFetcher<T extends Serializable> extends Serializable {
37+
ListResult<T> nextPage();
38+
}
39+
40+
public ListResult(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
41+
this.pageFetcher = pageFetcher;
3642
this.cursor = cursor;
3743
this.results = results;
3844
}
3945

46+
/**
47+
* Returns the cursor for the nextPage or {@code null} if no more results.
48+
*/
4049
public String nextPageCursor() {
4150
return cursor;
4251
}
4352

53+
/**
54+
* Returns the results of the nextPage or {@code null} if no more result.
55+
*/
56+
public ListResult<T> nextPage() {
57+
if (cursor == null || pageFetcher == null) {
58+
return null;
59+
}
60+
return pageFetcher.nextPage();
61+
}
62+
4463
@Override
4564
public Iterator<T> iterator() {
4665
return results == null ? Collections.<T>emptyIterator() : results.iterator();

0 commit comments

Comments
 (0)