diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java index fcbfe5514d1e..ec4447d406cb 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java @@ -14,6 +14,7 @@ package com.google.gcloud.spi; +import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.gcloud.spi.StorageRpc.Option.DELIMITER; import static com.google.gcloud.spi.StorageRpc.Option.FIELDS; import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_MATCH; @@ -58,7 +59,6 @@ import com.google.api.services.storage.model.Objects; import com.google.api.services.storage.model.StorageObject; import com.google.common.base.Function; -import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -167,24 +167,29 @@ public Tuple> list(final String bucket, Map storageObjects = Iterables.concat( - objects.getItems() != null ? objects.getItems() : ImmutableList.of(), + firstNonNull(objects.getItems(), ImmutableList.of()), objects.getPrefixes() != null - ? Lists.transform(objects.getPrefixes(), new Function() { - @Override - public StorageObject apply(String prefix) { - return new StorageObject() - .set("isDirectory", true) - .setBucket(bucket) - .setName(prefix) - .setSize(BigInteger.ZERO); - } - }) : ImmutableList.of()); + ? Lists.transform(objects.getPrefixes(), objectFromPrefix(bucket)) + : ImmutableList.of()); return Tuple.of(objects.getNextPageToken(), storageObjects); } catch (IOException ex) { throw translate(ex); } } + private static Function objectFromPrefix(final String bucket) { + return new Function() { + @Override + public StorageObject apply(String prefix) { + return new StorageObject() + .set("isDirectory", true) + .setBucket(bucket) + .setName(prefix) + .setSize(BigInteger.ZERO); + } + }; + } + @Override public Bucket get(Bucket bucket, Map options) { try { @@ -549,7 +554,7 @@ public String open(StorageObject object, Map options) { HttpRequest httpRequest = requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, object)); httpRequest.getHeaders().set("X-Upload-Content-Type", - MoreObjects.firstNonNull(object.getContentType(), "application/octet-stream")); + firstNonNull(object.getContentType(), "application/octet-stream")); HttpResponse response = httpRequest.execute(); if (response.getStatusCode() != 200) { GoogleJsonError error = new GoogleJsonError(); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java index 9d981aeeafda..cf509c8f0961 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java @@ -603,7 +603,7 @@ public Long updateTime() { /** * Returns {@code true} if the current blob represents a directory. This can only happen if the * blob is returned by {@link Storage#list(String, Storage.BlobListOption...)} when the - * {@link Storage.BlobListOption#currentDirectory()} option is used. If {@code true} only + * {@link Storage.BlobListOption#currentDirectory()} option is used. When this is the case only * {@link #blobId()} and {@link #size()} are set for the current blob: {@link BlobId#name()} ends * with the '/' character, {@link BlobId#generation()} returns {@code null} and {@link #size()} is * {@code 0}. @@ -785,7 +785,7 @@ public Acl apply(ObjectAccessControl objectAccessControl) { } })); } - if (storageObject.get("isDirectory") != null) { + if (storageObject.containsKey("isDirectory")) { builder.isDirectory(Boolean.TRUE); } return builder.build(); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java index e1ab337cdbdf..0ee18f541284 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java @@ -694,14 +694,14 @@ public static BlobListOption prefix(String prefix) { } /** - * If specified, results are returned in a directory-like mode. Blobs whose names, aside from - * a possible {@link #prefix(String)}, do not contain the '/' delimiter are returned as is. - * Blobs whose names, aside from a possible {@link #prefix(String)}, contain the '/' delimiter, - * will have their name truncated after the delimiter and will be returned as {@link Blob} - * objects where only {@link Blob#blobId()}, {@link Blob#size()} and {@link Blob#isDirectory()} - * are set. For such directory blobs, ({@link BlobId#generation()} returns {@code null}), - * {@link Blob#size()} returns {@code 0} while {@link Blob#isDirectory()} returns {@code true}. - * Duplicate directory blobs are omitted. + * If specified, results are returned in a directory-like mode. Blobs whose names, after a + * possible {@link #prefix(String)}, do not contain the '/' delimiter are returned as is. Blobs + * whose names, after a possible {@link #prefix(String)}, contain the '/' delimiter, will have + * their name truncated after the delimiter and will be returned as {@link Blob} objects where + * only {@link Blob#blobId()}, {@link Blob#size()} and {@link Blob#isDirectory()} are set. For + * such directory blobs, ({@link BlobId#generation()} returns {@code null}), {@link Blob#size()} + * returns {@code 0} while {@link Blob#isDirectory()} returns {@code true}. Duplicate directory + * blobs are omitted. */ public static BlobListOption currentDirectory() { return new BlobListOption(StorageRpc.Option.DELIMITER, true); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageOptions.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageOptions.java index ca9b8944ea8b..86ce18eb71ec 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageOptions.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageOptions.java @@ -106,11 +106,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof StorageOptions)) { - return false; - } - StorageOptions other = (StorageOptions) obj; - return baseEquals(other); + return obj instanceof StorageOptions && baseEquals((StorageOptions) obj); } public static Builder builder() {