Skip to content

Commit

Permalink
Replace given null values with Apiary nulls and provide doesNotExists…
Browse files Browse the repository at this point in the history
… option
  • Loading branch information
aozarov committed May 13, 2015
1 parent 4b8bd32 commit 96b3ada
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
42 changes: 22 additions & 20 deletions src/main/java/com/google/gcloud/storage/Blob.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.google.gcloud.storage;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.util.Data;
import com.google.api.client.util.DateTime;
import com.google.api.services.storage.model.ObjectAccessControl;
import com.google.api.services.storage.model.StorageObject;
Expand Down Expand Up @@ -124,22 +126,22 @@ public Builder name(String name) {
}

public Builder contentType(String contentType) {
this.contentType = contentType;
this.contentType = firstNonNull(contentType, Data.<String>nullOf(String.class));
return this;
}

public Builder contentDisposition(String contentDisposition) {
this.contentDisposition = contentDisposition;
this.contentDisposition = firstNonNull(contentDisposition, Data.<String>nullOf(String.class));
return this;
}

public Builder contentLanguage(String contentLanguage) {
this.contentLanguage = contentLanguage;
this.contentLanguage = firstNonNull(contentLanguage, Data.<String>nullOf(String.class));
return this;
}

public Builder contentEncoding(String contentEncoding) {
this.contentEncoding = contentEncoding;
this.contentEncoding = firstNonNull(contentEncoding, Data.<String>nullOf(String.class));
return this;
}

Expand All @@ -149,7 +151,7 @@ Builder componentCount(Integer componentCount) {
}

public Builder cacheControl(String cacheControl) {
this.cacheControl = cacheControl;
this.cacheControl = firstNonNull(cacheControl, Data.<String>nullOf(String.class));
return this;
}

Expand Down Expand Up @@ -179,12 +181,12 @@ Builder selfLink(String selfLink) {
}

public Builder md5(String md5) {
this.md5 = md5;
this.md5 = firstNonNull(md5, Data.<String>nullOf(String.class));
return this;
}

public Builder crc32c(String crc32c) {
this.crc32c = crc32c;
this.crc32c = firstNonNull(crc32c, Data.<String>nullOf(String.class));
return this;
}

Expand Down Expand Up @@ -263,7 +265,7 @@ public String name() {
}

public String cacheControl() {
return cacheControl;
return Data.isNull(cacheControl) ? null : cacheControl;
}

public List<Acl> acl() {
Expand All @@ -279,19 +281,19 @@ public Long size() {
}

public String contentType() {
return contentType;
return Data.isNull(contentType) ? null : contentType;
}

public String contentEncoding() {
return contentEncoding;
return Data.isNull(contentEncoding) ? null : contentEncoding;
}

public String contentDisposition() {
return contentDisposition;
return Data.isNull(contentDisposition) ? null : contentDisposition;
}

public String contentLanguage() {
return contentEncoding;
return Data.isNull(contentLanguage) ? null : contentLanguage;
}

public Integer componentCount() {
Expand All @@ -307,11 +309,11 @@ public String selfLink() {
}

public String md5() {
return md5;
return Data.isNull(md5) ? null : md5;
}

public String crc32c() {
return crc32c;
return Data.isNull(crc32c) ? null : crc32c;
}

public String mediaLink() {
Expand Down Expand Up @@ -367,11 +369,11 @@ public Builder toBuilder() {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("bucket", bucket)
.add("name", name)
.add("size", size)
.add("content-type", contentType)
.add("metadata", metadata)
.add("bucket", bucket())
.add("name", name())
.add("size", size())
.add("content-type", contentType())
.add("metadata", metadata())
.toString();
}

Expand All @@ -397,7 +399,7 @@ public boolean equals(Object obj) {
if (!(obj instanceof Blob)) {
return false;
}
return Objects.equals(toPb(), ((Blob)obj).toPb());
return Objects.equals(toPb(), ((Blob) obj).toPb());
}

StorageObject toPb() {
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/google/gcloud/storage/Bucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.google.gcloud.storage;

import static com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.Lists.transform;

import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.Data;
import com.google.api.client.util.DateTime;
import com.google.api.services.storage.model.Bucket.Lifecycle;
import com.google.api.services.storage.model.Bucket.Lifecycle.Rule;
Expand Down Expand Up @@ -67,7 +69,6 @@ public final class Bucket implements Serializable {
private final Location location;
private final StorageClass storageClass;


static final Function<com.google.api.services.storage.model.Bucket, Bucket> FROM_PB_FUNCTION =
new Function<com.google.api.services.storage.model.Bucket, Bucket>() {
@Override
Expand Down Expand Up @@ -248,6 +249,9 @@ public static final class StorageClass implements Serializable {

private static final long serialVersionUID = 374002156285326563L;
private static final ImmutableMap<String, Option> STRING_TO_OPTION;
private static final StorageClass NULL_VALUE =
new StorageClass(Data.<String>nullOf(String.class));

private final String value;

public enum Option {
Expand Down Expand Up @@ -299,6 +303,8 @@ public static final class Location implements Serializable {

private static final long serialVersionUID = 9073107666838637662L;
private static final ImmutableMap<String, Option> STRING_TO_OPTION;
private static final Location NULL_VALUE = new Location(Data.<String>nullOf(String.class));

private final String value;

public enum Option {
Expand Down Expand Up @@ -392,7 +398,7 @@ Builder selfLink(String selfLink) {
}

public Builder versioningEnabled(Boolean enable) {
this.versioningEnabled = enable;
this.versioningEnabled = firstNonNull(enable, Data.<Boolean>nullOf(Boolean.class));
return this;
}

Expand All @@ -412,12 +418,12 @@ public Builder deleteRules(Iterable<DeleteRule> rules) {
}

public Builder storageClass(StorageClass storageClass) {
this.storageClass = storageClass;
this.storageClass = firstNonNull(storageClass, StorageClass.NULL_VALUE);
return this;
}

public Builder location(Location location) {
this.location = location;
this.location = firstNonNull(location, Location.NULL_VALUE);
return this;
}

Expand Down Expand Up @@ -493,7 +499,7 @@ public String selfLink() {
}

public Boolean versioningEnabled() {
return versioningEnabled;
return Data.isNull(versioningEnabled) ? null : versioningEnabled;
}

public String indexPage() {
Expand Down Expand Up @@ -521,11 +527,11 @@ public Long metageneration() {
}

public Location location() {
return location;
return location == null || Data.isNull(location.value) ? null : location;
}

public StorageClass storageClass() {
return storageClass;
return storageClass == null || Data.isNull(storageClass.value) ? null : storageClass;
}

public List<Cors> cors() {
Expand Down Expand Up @@ -576,7 +582,7 @@ public boolean equals(Object obj) {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", name)
.add("name", name())
.toString();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/google/gcloud/storage/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public static BlobTargetOption predefinedAcl(PredefinedAcl acl) {
return new BlobTargetOption(StorageRpc.Option.PREDEFINED_ACL, acl.entry());
}

public static BlobTargetOption doesNotExists() {

This comment has been minimized.

Copy link
@Capstan

Capstan May 20, 2015

Contributor

s/doesNotExists/doesNotExist/

This comment has been minimized.

Copy link
@aozarov

aozarov May 20, 2015

Author Contributor

Thank you. will fix it.

return new BlobTargetOption(StorageRpc.Option.IF_GENERATION_MATCH, 0);
}

public static BlobTargetOption generationMatch() {
return new BlobTargetOption(StorageRpc.Option.IF_GENERATION_MATCH);
}
Expand Down

0 comments on commit 96b3ada

Please sign in to comment.