Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding an option to page from ListResult #68

Merged
merged 5 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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