Skip to content

Commit

Permalink
Merge remote-tracking branch and fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed May 19, 2015
2 parents b9b4383 + c120b68 commit 3c91299
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/ServiceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public AuthCredentials authCredentials() {
}

public RetryParams retryParams() {
return retryParams;
return retryParams != null ? retryParams : RetryParams.noRetries();
}

public ServiceRpcFactory<R, O> serviceRpcFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DatastoreServiceOptions extends ServiceOptions<DatastoreRpc, Datast
private final String namespace;
private final boolean force;
private final boolean normalizeDataset;
private transient DatastoreRpc datastoreRpc;

public static class Builder extends
ServiceOptions.Builder<DatastoreRpc, DatastoreServiceOptions, Builder> {
Expand Down Expand Up @@ -178,10 +179,15 @@ public boolean equals(Object obj) {
}

DatastoreRpc datastoreRpc() {
if (datastoreRpc != null) {
return datastoreRpc;
}
if (serviceRpcFactory() != null) {
return serviceRpcFactory().create(this);
datastoreRpc = serviceRpcFactory().create(this);
} else {
datastoreRpc = ServiceRpcProvider.datastore(this);
}
return ServiceRpcProvider.datastore(this);
return datastoreRpc;
}

public static DatastoreServiceOptions defaultInstance() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/gcloud/storage/BatchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public boolean equals(Object obj) {
&& Objects.equals(toGet, other.toGet);
}

Map<Blob, Iterable<BlobSourceOption>> toDelete() {
public Map<Blob, Iterable<BlobSourceOption>> toDelete() {
return toDelete;
}

Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
public Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
return toUpdate;
}

Map<Blob, Iterable<BlobSourceOption>> toGet() {
public Map<Blob, Iterable<BlobSourceOption>> toGet() {
return toGet;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/gcloud/storage/BatchResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public static class Result<T extends Serializable> implements Serializable {
private final StorageServiceException exception;


Result(T value) {
public Result(T value) {
this.value = value;
this.exception = null;
}

Result(StorageServiceException exception) {
public Result(StorageServiceException exception) {
this.exception = exception;
this.value = null;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ static <T extends Serializable> Result<T> empty() {
}
}

BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
List<Result<Blob>> getResult) {
this.deleteResult = ImmutableList.copyOf(deleteResult);
this.updateResult = ImmutableList.copyOf(updateResult);
Expand Down
43 changes: 39 additions & 4 deletions src/main/java/com/google/gcloud/storage/Bucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ public Type type() {
return type;
}

@Override
public int hashCode() {
return Objects.hash(type);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final DeleteRule other = (DeleteRule) obj;
return Objects.equals(toPb(), other.toPb());
}

Rule toPb() {
Rule rule = new Rule();
rule.setAction(new Rule.Action().setType(SUPPORTED_ACTION));
Expand All @@ -114,7 +131,7 @@ Rule toPb() {

abstract void populateCondition(Rule.Condition condition);

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

@Override
public int hashCode() {
return Objects.hash(value);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Location other = (Location) obj;
return Objects.equals(this.value, other.value);
}

@Override
public String toString() {
return value();
Expand Down Expand Up @@ -412,7 +446,7 @@ public Builder notFoundPage(String notFoundPage) {
return this;
}

public Builder deleteRules(Iterable<DeleteRule> rules) {
public Builder deleteRules(Iterable<? extends DeleteRule> rules) {
this.deleteRules = ImmutableList.copyOf(rules);
return this;
}
Expand Down Expand Up @@ -490,7 +524,7 @@ public String name() {
return name;
}

public Entity Owner() {
public Entity owner() {
return owner;
}

Expand All @@ -510,7 +544,7 @@ public String notFoundPage() {
return notFoundPage;
}

public List<DeleteRule> deleteRules() {
public List<? extends DeleteRule> deleteRules() {
return deleteRules;
}

Expand Down Expand Up @@ -652,6 +686,7 @@ public Rule apply(DeleteRule deleteRule) {
return deleteRule.toPb();
}
}));
bucketPb.setLifecycle(lifecycle);
}
return bucketPb;
}
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/com/google/gcloud/storage/Cors.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ public Builder maxAgeSeconds(Integer maxAgeSeconds) {
}

public Builder methods(Iterable<Method> methods) {
this.methods = ImmutableList.copyOf(methods);
this.methods = methods != null ? ImmutableList.copyOf(methods) : null;
return this;
}

public Builder origins(Iterable<Origin> origins) {
this.origins = ImmutableList.copyOf(origins);
this.origins = origins != null ? ImmutableList.copyOf(origins) : null;
return this;
}

public Builder responseHeaders(Iterable<String> headers) {
this.responseHeaders = ImmutableList.copyOf(headers);
this.responseHeaders = headers != null ? ImmutableList.copyOf(headers) : null;
return this;
}

Expand Down Expand Up @@ -205,25 +205,33 @@ Bucket.Cors toPb() {
Bucket.Cors pb = new Bucket.Cors();
pb.setMaxAgeSeconds(maxAgeSeconds);
pb.setResponseHeader(responseHeaders);
pb.setMethod(newArrayList(transform(methods(), Functions.toStringFunction())));
pb.setOrigin(newArrayList(transform(origins(), Functions.toStringFunction())));
if (methods != null) {
pb.setMethod(newArrayList(transform(methods, Functions.toStringFunction())));
}
if (origins != null) {
pb.setOrigin(newArrayList(transform(origins, Functions.toStringFunction())));
}
return pb;
}

static Cors fromPb(Bucket.Cors cors) {
Builder builder = builder().maxAgeSeconds(cors.getMaxAgeSeconds());
builder.methods(transform(cors.getMethod(), new Function<String, Method>() {
@Override
public Method apply(String name) {
return Method.valueOf(name.toUpperCase());
}
}));
builder.origins(transform(cors.getOrigin(), new Function<String, Origin>() {
@Override
public Origin apply(String value) {
return Origin.of(value);
}
}));
if (cors.getMethod() != null) {
builder.methods(transform(cors.getMethod(), new Function<String, Method>() {
@Override
public Method apply(String name) {
return Method.valueOf(name.toUpperCase());
}
}));
}
if (cors.getOrigin() != null) {
builder.origins(transform(cors.getOrigin(), new Function<String, Origin>() {
@Override
public Origin apply(String value) {
return Origin.of(value);
}
}));
}
builder.responseHeaders(cors.getResponseHeader());
return builder.build();
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/google/gcloud/storage/ListResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,35 @@ public final class ListResult<T extends Serializable> implements Iterable<T>, Se

private final String cursor;
private final Iterable<T> results;
private final NextPageFetcher<T> pageFetcher;

ListResult(String cursor, Iterable<T> results) {
interface NextPageFetcher<T extends Serializable> extends Serializable {
ListResult<T> nextPage();
}

public ListResult(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
this.pageFetcher = pageFetcher;
this.cursor = cursor;
this.results = results;
}

/**
* Returns the cursor for the nextPage or {@code null} if no more results.
*/
public String nextPageCursor() {
return cursor;
}

/**
* Returns the results of the nextPage or {@code null} if no more result.
*/
public ListResult<T> nextPage() {
if (cursor == null || pageFetcher == null) {
return null;
}
return pageFetcher.nextPage();
}

@Override
public Iterator<T> iterator() {
return results == null ? Collections.<T>emptyIterator() : results.iterator();
Expand Down
Loading

0 comments on commit 3c91299

Please sign in to comment.