diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java b/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java index 6cdb737ddd91..13d91836ae4c 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java @@ -181,10 +181,9 @@ public static AuthCredentials createForComputeEngine() /** * Returns the Application Default Credentials. * - *

- * Returns the Application Default Credentials which are credentials that identify and authorize - * the whole application. This is the built-in service account if running on Google Compute Engine - * or the credentials file from the path in the environment variable + *

Returns the Application Default Credentials which are credentials that identify and + * authorize the whole application. This is the built-in service account if running on + * Google Compute Engine or the credentials file from the path in the environment variable * GOOGLE_APPLICATION_CREDENTIALS. *

* diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/BaseService.java b/gcloud-java-core/src/main/java/com/google/gcloud/BaseService.java index 02bfd76771b2..982d3058295c 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/BaseService.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/BaseService.java @@ -16,16 +16,17 @@ package com.google.gcloud; -public abstract class BaseService implements Service { +public abstract class BaseService> + implements Service { - private final O options; + private final OptionsT options; - protected BaseService(O options) { + protected BaseService(OptionsT options) { this.options = options; } @Override - public O options() { + public OptionsT options() { return options; } } diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/Service.java b/gcloud-java-core/src/main/java/com/google/gcloud/Service.java index 8a43b9cf2244..19759fb20e21 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/Service.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/Service.java @@ -16,6 +16,6 @@ package com.google.gcloud; -public interface Service { - O options(); +public interface Service> { + OptionsT options(); } diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java index a974a1f1912a..cd529ba14187 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java @@ -45,7 +45,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public abstract class ServiceOptions> implements Serializable { +public abstract class ServiceOptions< + ServiceRpcT, + OptionsT extends ServiceOptions> + implements Serializable { private static final String DEFAULT_HOST = "https://www.googleapis.com"; private static final long serialVersionUID = 1203687993961393350L; @@ -56,7 +59,7 @@ public abstract class ServiceOptions> implemen private final HttpTransportFactory httpTransportFactory; private final AuthCredentials authCredentials; private final RetryParams retryParams; - private final ServiceRpcFactory serviceRpcFactory; + private final ServiceRpcFactory serviceRpcFactory; public interface HttpTransportFactory extends Serializable { HttpTransport create(); @@ -88,19 +91,21 @@ public HttpTransport create() { - protected abstract static class Builder, - B extends Builder> { + protected abstract static class Builder< + ServiceRpcT, + OptionsT extends ServiceOptions, + B extends Builder> { private String projectId; private String host; private HttpTransportFactory httpTransportFactory; private AuthCredentials authCredentials; private RetryParams retryParams; - private ServiceRpcFactory serviceRpcFactory; + private ServiceRpcFactory serviceRpcFactory; protected Builder() {} - protected Builder(ServiceOptions options) { + protected Builder(ServiceOptions options) { projectId = options.projectId; host = options.host; httpTransportFactory = options.httpTransportFactory; @@ -109,7 +114,7 @@ protected Builder(ServiceOptions options) { serviceRpcFactory = options.serviceRpcFactory; } - protected abstract ServiceOptions build(); + protected abstract ServiceOptions build(); @SuppressWarnings("unchecked") protected B self() { @@ -141,13 +146,13 @@ public B retryParams(RetryParams retryParams) { return self(); } - public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { + public B serviceRpcFactory(ServiceRpcFactory serviceRpcFactory) { this.serviceRpcFactory = serviceRpcFactory; return self(); } } - protected ServiceOptions(Builder builder) { + protected ServiceOptions(Builder builder) { projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject()); host = firstNonNull(builder.host, DEFAULT_HOST); httpTransportFactory = @@ -222,7 +227,7 @@ protected static String googleCloudProjectId() { String section = null; Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$"); Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$"); - while((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null) { if (line.isEmpty() || line.startsWith(";")) { continue; } @@ -245,7 +250,7 @@ protected static String googleCloudProjectId() { } private static boolean isWindows() { - return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1; + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } protected static String getAppEngineProjectId() { @@ -288,7 +293,7 @@ public RetryParams retryParams() { return retryParams != null ? retryParams : RetryParams.noRetries(); } - public ServiceRpcFactory serviceRpcFactory() { + public ServiceRpcFactory serviceRpcFactory() { return serviceRpcFactory; } @@ -297,13 +302,12 @@ public HttpRequestInitializer httpRequestInitializer() { return authCredentials().httpRequestInitializer(httpTransport, scopes()); } - @Override - public int hashCode() { + protected int baseHashCode() { return Objects.hash(projectId, host, httpTransportFactory, authCredentials, retryParams, serviceRpcFactory); } - protected boolean isEquals(ServiceOptions other) { + protected boolean baseEquals(ServiceOptions other) { return Objects.equals(projectId, other.projectId) && Objects.equals(host, other.host) && Objects.equals(httpTransportFactory, other.httpTransportFactory) @@ -312,14 +316,17 @@ protected boolean isEquals(ServiceOptions other) { && Objects.equals(serviceRpcFactory, other.serviceRpcFactory); } - public abstract Builder toBuilder(); + public abstract Builder toBuilder(); /** * Creates a service RPC using a factory loaded by {@link ServiceLoader}. */ - protected static > R createRpc(O options, - Class> factoryClass) { - ServiceRpcFactory factory = Iterables.getFirst(ServiceLoader.load(factoryClass), null); + protected static + > + ServiceRpcT createRpc(OptionsT options, + Class> factoryClass) { + ServiceRpcFactory factory = + Iterables.getFirst(ServiceLoader.load(factoryClass), null); return factory == null ? null : factory.create(options); } } diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java b/gcloud-java-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java index 9bab3f81ce9c..89e08cda9eda 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/spi/ServiceRpcFactory.java @@ -24,7 +24,10 @@ * A base interface for all service RPC factories. * Loading of a factory implementation is done via {@link java.util.ServiceLoader}. */ -public interface ServiceRpcFactory extends Serializable { +public interface ServiceRpcFactory< + ServiceRpcT, + OptionsT extends ServiceOptions> + extends Serializable { - S create(O options); + ServiceRpcT create(OptionsT options); } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java index 21e20b33a8ed..3a79f3053a1e 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java @@ -40,12 +40,13 @@ /** * A base class for entities (key and properties). - * An entity is Google Cloud Datastore persistent data object. + * An entity is a Google Cloud Datastore persistent data object. * An entity holds one or more properties, represented by a name (as {@link String}) * and a value (as {@link com.google.gcloud.datastore.Value}), and may be associated with a * key. For a list of possible values see {@link ValueType}. * - * @see Google Cloud Datastore Entities, Properties, and Keys + * @see Google Cloud Datastore + * Entities, Properties, and Keys */ public abstract class BaseEntity extends Serializable { @@ -54,7 +55,7 @@ public abstract class BaseEntity extends Serializable> properties; private final K key; - abstract static class Builder> { + public abstract static class Builder> { private K key; private final Map> properties = new HashMap<>(); @@ -127,7 +128,7 @@ public B remove(String name) { return self(); } - public B set(String name, Value value) { + public B set(String name, Value value) { properties.put(name, value); return self(); } @@ -187,7 +188,7 @@ public B setNull(String name) { return self(); } - public abstract BaseEntity build(); + public abstract BaseEntity build(); } BaseEntity(Builder builder) { @@ -213,7 +214,7 @@ public boolean equals(Object obj) { if (!(obj instanceof BaseEntity)) { return false; } - BaseEntity other = (BaseEntity) obj; + BaseEntity other = (BaseEntity) obj; return Objects.equals(key, other.key) && Objects.equals(properties, other.properties); } @@ -254,7 +255,7 @@ public > V getValue(String name) { } /** - * Returns true if property is instanceof NullValue. + * Returns true if property is an instance of NullValue. * * @throws DatastoreException if not such property. */ @@ -375,12 +376,12 @@ ImmutableSortedMap> properties() { @Override protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException { - Builder builder = emptyBuilder(); + Builder builder = emptyBuilder(); builder.fill(DatastoreV1.Entity.parseFrom(bytesPb)); return builder.build(); } - protected abstract Builder emptyBuilder(); + protected abstract Builder emptyBuilder(); @Override protected final DatastoreV1.Entity toPb() { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java index 9c95949e2c8a..8cb41304500b 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java @@ -34,7 +34,7 @@ static class ResponseImpl implements Batch.Response { private final DatastoreV1.CommitResponse response; - public ResponseImpl(DatastoreV1.CommitResponse response) { + ResponseImpl(DatastoreV1.CommitResponse response) { this.response = response; } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Datastore.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Datastore.java index fe79fdf45ff4..870ed8d9474f 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Datastore.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Datastore.java @@ -34,7 +34,7 @@ public interface Datastore extends Service, DatastoreReaderWri /** - * An Callback for running with a Transactional + * A callback for running with a transactional * {@link com.google.gcloud.datastore.DatastoreReaderWriter}. * The associated transaction will be committed after a successful return from the {@code run} * method. Any propagated exception will cause the transaction to be rolled-back. diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java index d91cc2ccd98b..562578a26428 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java @@ -37,7 +37,8 @@ public class DatastoreException extends RuntimeException { /** * An error code to represent the failure. * - * @see Google Cloud Datastore error codes + * @see Google Cloud + * Datastore error codes */ public enum Code { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java index e848dd5e56c8..6f2454c62167 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java @@ -17,12 +17,10 @@ package com.google.gcloud.datastore; import com.google.api.services.datastore.DatastoreV1; -import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterators; import com.google.common.collect.Sets; import com.google.gcloud.BaseService; import com.google.gcloud.ExceptionHandler; @@ -131,15 +129,11 @@ public List allocateId(IncompleteKey... keys) { requestPb.addKey(trimNameOrId(key).toPb()); } DatastoreV1.AllocateIdsResponse responsePb = allocateIds(requestPb.build()); - Iterator keyIterator = responsePb.getKeyList().iterator(); - ImmutableList.Builder builder = ImmutableList.builder().addAll( - Iterators.transform(keyIterator, new Function() { - @Override - public Key apply(DatastoreV1.Key keyPb) { - return Key.fromPb(keyPb); - } - })); - return builder.build(); + ImmutableList.Builder keyList = ImmutableList.builder(); + for (DatastoreV1.Key keyPb : responsePb.getKeyList()) { + keyList.add(Key.fromPb(keyPb)); + } + return keyList.build(); } DatastoreV1.AllocateIdsResponse allocateIds(final DatastoreV1.AllocateIdsRequest requestPb) { @@ -256,9 +250,6 @@ private void loadResults() { @SuppressWarnings("unchecked") @Override protected Entity computeNext() { - if (iter.hasNext()) { - return Entity.fromPb(iter.next().getEntity()); - } while (!iter.hasNext()) { if (requestPb.getKeyCount() == 0) { return endOfData(); diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java index ed6b51458938..c670bb5d9a2d 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java @@ -165,7 +165,7 @@ public Builder toBuilder() { @Override public int hashCode() { - return super.hashCode() ^ Objects.hash(namespace, force, normalizeDataset); + return baseHashCode() ^ Objects.hash(namespace, force, normalizeDataset); } @Override @@ -174,7 +174,7 @@ public boolean equals(Object obj) { return false; } DatastoreOptions other = (DatastoreOptions) obj; - return isEquals(other) && Objects.equals(namespace, other.namespace) + return baseEquals(other) && Objects.equals(namespace, other.namespace) && Objects.equals(force, other.force) && Objects.equals(normalizeDataset, other.normalizeDataset); } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java index 853856c1b696..af5a17ef7ef3 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java @@ -31,7 +31,8 @@ * A Google Cloud Datastore timestamp (represented in micro-seconds). * This class is immutable. * - * @see Google Cloud Datastore Entities, Properties, and Keys + * @see Google Cloud Datastore + * Entities, Properties, and Keys */ public final class DateTime extends Serializable implements Comparable { @@ -61,8 +62,9 @@ public int compareTo(DateTime other) { @Override public boolean equals(Object obj) { - return obj == this || obj instanceof DateTime - && timestampMicroseconds == ((DateTime) obj).timestampMicroseconds; + return obj == this + || (obj instanceof DateTime + && timestampMicroseconds == ((DateTime) obj).timestampMicroseconds); } public long timestampMicroseconds() { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Entity.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Entity.java index 7842fba61f0c..dc1af5b8a2d9 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Entity.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Entity.java @@ -70,7 +70,7 @@ public Entity build() { } @Override - protected BaseEntity.Builder emptyBuilder() { + protected BaseEntity.Builder emptyBuilder() { return new Builder(); } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityValue.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityValue.java index add50e1747b3..da32c8eb2462 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityValue.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityValue.java @@ -21,12 +21,12 @@ import com.google.api.services.datastore.DatastoreV1; import com.google.common.base.Preconditions; -public class EntityValue extends Value { +public class EntityValue extends Value> { private static final long serialVersionUID = -5461475706792576395L; - static final BaseMarshaller MARSHALLER = - new BaseMarshaller() { + static final BaseMarshaller, EntityValue, Builder> MARSHALLER = + new BaseMarshaller, EntityValue, Builder>() { private static final long serialVersionUID = 2355075086076070931L; @@ -36,12 +36,12 @@ public int getProtoFieldId() { } @Override - public Builder newBuilder(FullEntity value) { + public Builder newBuilder(FullEntity value) { return builder(value); } @Override - protected FullEntity getValue(DatastoreV1.Value from) { + protected FullEntity getValue(DatastoreV1.Value from) { return FullEntity.fromPb(from.getEntityValue()); } @@ -51,7 +51,7 @@ protected void setValue(EntityValue from, DatastoreV1.Value.Builder to) { } }; - public static final class Builder extends Value.BaseBuilder { + public static final class Builder extends Value.BaseBuilder, EntityValue, Builder> { private Builder() { super(ValueType.ENTITY); @@ -70,7 +70,7 @@ public EntityValue build() { } } - public EntityValue(FullEntity entity) { + public EntityValue(FullEntity entity) { this(builder(entity)); } @@ -83,11 +83,11 @@ public Builder toBuilder() { return new Builder().mergeFrom(this); } - public static EntityValue of(FullEntity entity) { + public static EntityValue of(FullEntity entity) { return new EntityValue(entity); } - public static Builder builder(FullEntity entity) { + public static Builder builder(FullEntity entity) { return new Builder().set(entity).indexed(false); } } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/FullEntity.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/FullEntity.java index d7084420665e..bb08fca12e3c 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/FullEntity.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/FullEntity.java @@ -53,8 +53,8 @@ public FullEntity build() { } @Override - protected BaseEntity.Builder emptyBuilder() { - return new Builder(); + protected BaseEntity.Builder emptyBuilder() { + return new Builder(); } public static Builder builder() { @@ -70,7 +70,7 @@ public static Builder builder(FullEntity copyFro } - static FullEntity fromPb(DatastoreV1.Entity entityPb) { + static FullEntity fromPb(DatastoreV1.Entity entityPb) { return new Builder<>().fill(entityPb).build(); } } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java index 60c22637da56..e9bd8e12cfd8 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java @@ -38,7 +38,7 @@ import java.util.TreeMap; /** - * A Google Cloud Datastore GQL. + * A Google Cloud Datastore GQL query. * *

A usage example:

* @@ -121,8 +121,8 @@ public boolean equals(Object obj) { } Binding other = (Binding) obj; return Objects.equals(name, other.name) - && Objects.equals(cursor, other.cursor) - && Objects.equals(value, other.value); + && Objects.equals(cursor, other.cursor) + && Objects.equals(value, other.value); } @Override @@ -286,17 +286,17 @@ public GqlQuery build() { return new GqlQuery<>(this); } - @SuppressWarnings("rawtypes") - private static Binding toBinding(Value.BuilderFactory builderFactory, List values) { + private static Binding toBinding(Value.BuilderFactory builderFactory, List values) { return toBinding(null, builderFactory, values); } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static Binding toBinding(String name, Value.BuilderFactory builderFactory, + private static Binding toBinding(String name, Value.BuilderFactory builderFactory, List values) { - List> list = new ArrayList<>(values.size()); + List> list = new ArrayList<>(values.size()); for (Object object : values) { - list.add(builderFactory.newBuilder(object).build()); + @SuppressWarnings("unchecked") + V v = (V) object; + list.add(builderFactory.newBuilder(v).build()); } Value value; if (list.isEmpty()) { @@ -400,7 +400,8 @@ protected Object fromPb(ResultType resultType, String namespace, byte[] bytes return fromPb(resultType, namespace, DatastoreV1.GqlQuery.parseFrom(bytesPb)); } - private static GqlQuery fromPb(ResultType resultType, String ns, DatastoreV1.GqlQuery queryPb) { + private static GqlQuery fromPb( + ResultType resultType, String ns, DatastoreV1.GqlQuery queryPb) { Builder builder = new Builder<>(resultType, queryPb.getQueryString()); builder.namespace(ns); if (queryPb.hasAllowLiteral()) { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Key.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Key.java index 8b04898ffcd0..c625c067f6c2 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Key.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Key.java @@ -33,7 +33,8 @@ * Google Cloud Datastore {@link Entity}. * This class is immutable. * - * @see Google Cloud Datastore Entities, Properties, and Keys + * @see Google Cloud Datastore + * Entities, Properties, and Keys */ public final class Key extends IncompleteKey { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyFactory.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyFactory.java index 8010468c5068..28f852ed5355 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyFactory.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyFactory.java @@ -19,7 +19,7 @@ import com.google.common.collect.ImmutableList; /** - * An helper for creating keys for a specific {@link Datastore}, + * A helper for creating keys for a specific {@link Datastore}, * using its associated projectId and namespace. */ public final class KeyFactory extends BaseKey.Builder { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ProjectionEntity.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ProjectionEntity.java index acd9783fe836..1ba054b68161 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ProjectionEntity.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ProjectionEntity.java @@ -24,14 +24,16 @@ * A projection entity holds one or more properties, represented by a name (as {@link String}) * and a value (as {@link Value}), and may have a {@link Key}. * - * @see Google Cloud Datastore projection queries - * @see Google Cloud Datastore Entities, Properties, and Keys + * @see Google Cloud + * Datastore projection queries + * @see Google Cloud Datastore + * Entities, Properties, and Keys */ public final class ProjectionEntity extends BaseEntity { private static final long serialVersionUID = 432961565733066915L; - static final class Builder extends BaseEntity.Builder { + public static final class Builder extends BaseEntity.Builder { Builder() { } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java index 093dc7283327..343535d94628 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java @@ -106,8 +106,7 @@ public abstract static class ResultType implements java.io.Serializable { private final Class resultClass; private final DatastoreV1.EntityResult.ResultType queryType; - @SuppressWarnings("unchecked") - private ResultType(DatastoreV1.EntityResult.ResultType queryType, Class resultClass) { + private ResultType(DatastoreV1.EntityResult.ResultType queryType, Class resultClass) { this.queryType = queryType; this.resultClass = resultClass; if (queryType != null) { @@ -115,7 +114,7 @@ private ResultType(DatastoreV1.EntityResult.ResultType queryType, Class resultCl } } - public Class resultClass() { + public Class resultClass() { return resultClass; } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResults.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResults.java index 44360987b573..b23c56a7c395 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResults.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResults.java @@ -20,9 +20,9 @@ /** * The result of a Google Cloud Datastore query submission. - * When result is not typed it is possible to cast it to its appropriate type according to + * When the result is not typed it is possible to cast it to its appropriate type according to * the {@link #resultClass} value. - * Results are loaded lazily therefore it is possible to get a {@code DatastoreException} + * Results are loaded lazily; therefore it is possible to get a {@code DatastoreException} * upon {@link Iterator#hasNext hasNext} or {@link Iterator#next next} calls. * * @param the type of the results value. diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java index 8e2f294ed15d..cd3fe9dd776b 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java @@ -76,7 +76,6 @@ private void sendRequest() { "Unexpected result type " + actualResultType + " vs " + queryResultType); } - @SuppressWarnings("unchecked") @Override protected T computeNext() { while (!entityResultPbIter.hasNext() && !lastBatch) { @@ -88,7 +87,9 @@ protected T computeNext() { } DatastoreV1.EntityResult entityResultPb = entityResultPbIter.next(); //cursor = entityResultPb.getCursor(); // only available in v1beta3 - return (T) actualResultType.convert(entityResultPb.getEntity()); + @SuppressWarnings("unchecked") + T result = (T) actualResultType.convert(entityResultPb.getEntity()); + return result; } @Override diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/RawValue.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/RawValue.java index 550d27804eba..9d447cf4289b 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/RawValue.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/RawValue.java @@ -48,7 +48,8 @@ protected void setValue(RawValue from, DatastoreV1.Value.Builder to) { } }; - static final class Builder extends Value.BaseBuilder { + public static final class Builder + extends Value.BaseBuilder { private Builder() { super(ValueType.RAW_VALUE); diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java index cb141b6218b0..ce596307d6da 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/StructuredQuery.java @@ -78,7 +78,8 @@ * } * * @param the type of the result values this query will produce - * @see Datastore queries + * @see Datastore + * queries */ public class StructuredQuery extends Query { diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionImpl.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionImpl.java index 48568650910d..ae677aa005d6 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionImpl.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionImpl.java @@ -38,7 +38,7 @@ static class ResponseImpl implements Transaction.Response { private final DatastoreV1.CommitResponse response; - public ResponseImpl(DatastoreV1.CommitResponse response) { + ResponseImpl(DatastoreV1.CommitResponse response) { this.response = response; } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueBuilder.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueBuilder.java index 99a44f19366a..f5b5d4c1319b 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueBuilder.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueBuilder.java @@ -19,7 +19,7 @@ /** * A common interface for Value builders. */ -interface ValueBuilder, B extends ValueBuilder> { +public interface ValueBuilder, B extends ValueBuilder> { ValueType getValueType(); diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueType.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueType.java index 5b515d6a0901..b09583103a59 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueType.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ValueType.java @@ -97,7 +97,8 @@ public enum ValueType { } - , B extends ValueBuilder> ValueType(ValueMarshaller marshaller) { + , B extends ValueBuilder> + ValueType(ValueMarshaller marshaller) { this.marshaller = marshaller; } diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DatastoreRpc.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DatastoreRpc.java index f4b7cd39587b..dffcc3f0e16f 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DatastoreRpc.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DatastoreRpc.java @@ -38,7 +38,8 @@ public class DatastoreRpcException extends Exception { /** * The reason for the exception. * - * @see Google Cloud Datastore error codes + * @see Google + * Cloud Datastore error codes */ public enum Reason { diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java index 9fe207a04056..ad8e0cee266a 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java @@ -16,11 +16,14 @@ package com.google.gcloud.datastore; -import static org.easymock.EasyMock.*; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import com.google.api.services.datastore.DatastoreV1; import com.google.common.collect.ImmutableList; + import org.easymock.EasyMock; import org.junit.After; import org.junit.Before; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java index 02ccd996dc83..5ece01508d3a 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java @@ -43,14 +43,14 @@ public class BaseEntityTest { private Builder builder; - private class Builder extends BaseEntity.Builder { + private class Builder extends BaseEntity.Builder { - @Override public BaseEntity build() { + @Override public BaseEntity build() { - return new BaseEntity(this) { + return new BaseEntity(this) { @Override - protected Builder emptyBuilder() { + protected BaseEntityTest.Builder emptyBuilder() { return new BaseEntityTest.Builder(); } }; @@ -71,7 +71,7 @@ public void setUp() { @Test public void testContains() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertTrue(entity.contains("list1")); assertFalse(entity.contains("bla")); entity = builder.clear().build(); @@ -80,19 +80,19 @@ public void testContains() throws Exception { @Test public void testGetValue() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(BlobValue.of(BLOB), entity.getValue("blob")); } @Test(expected = DatastoreException.class) public void testGetValueNotFound() throws Exception { - BaseEntity entity = builder.clear().build(); + BaseEntity entity = builder.clear().build(); entity.getValue("blob"); } @Test public void testIsNull() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertTrue(entity.isNull("null")); assertFalse(entity.isNull("blob")); entity = builder.setNull("blob").build(); @@ -101,13 +101,13 @@ public void testIsNull() throws Exception { @Test(expected = DatastoreException.class) public void testIsNullNotFound() throws Exception { - BaseEntity entity = builder.clear().build(); + BaseEntity entity = builder.clear().build(); entity.isNull("null"); } @Test public void testGetString() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals("hello world", entity.getString("string")); assertEquals("bla", entity.getString("stringValue")); entity = builder.set("string", "foo").build(); @@ -116,7 +116,7 @@ public void testGetString() throws Exception { @Test public void testGetLong() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(125, entity.getLong("long")); entity = builder.set("long", LongValue.of(10)).build(); assertEquals(10, entity.getLong("long")); @@ -124,7 +124,7 @@ public void testGetLong() throws Exception { @Test public void testGetDouble() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(1.25, entity.getDouble("double"), 0); entity = builder.set("double", DoubleValue.of(10)).build(); assertEquals(10, entity.getDouble("double"), 0); @@ -132,7 +132,7 @@ public void testGetDouble() throws Exception { @Test public void testGetBoolean() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertTrue(entity.getBoolean("boolean")); entity = builder.set("boolean", BooleanValue.of(false)).build(); assertFalse(entity.getBoolean("boolean")); @@ -140,7 +140,7 @@ public void testGetBoolean() throws Exception { @Test public void testGetDateTime() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(DATE_TIME, entity.getDateTime("dateTime")); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); @@ -151,7 +151,7 @@ public void testGetDateTime() throws Exception { @Test public void testGetKey() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(KEY, entity.getKey("key")); Key key = Key.builder(KEY).name("BLA").build(); entity = builder.set("key", key).build(); @@ -160,7 +160,7 @@ public void testGetKey() throws Exception { @Test public void testGetEntity() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(ENTITY, entity.getEntity("entity")); assertEquals(PARTIAL_ENTITY, entity.getEntity("partialEntity")); entity = builder.set("entity", EntityValue.of(PARTIAL_ENTITY)).build(); @@ -169,7 +169,7 @@ public void testGetEntity() throws Exception { @Test public void testGetList() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); List> list = entity.getList("list1"); assertEquals(2, list.size()); assertEquals(NullValue.of(), list.get(0)); @@ -187,7 +187,7 @@ public void testGetList() throws Exception { @Test public void testGetBlob() throws Exception { - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(BLOB, entity.getBlob("blob")); Blob blob = Blob.copyFrom(new byte[] {}); entity = builder.set("blob", BlobValue.of(blob)).build(); @@ -200,7 +200,7 @@ public void testNames() throws Exception { .add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3") .add("entity", "partialEntity", "null", "dateTime", "blob", "key") .build(); - BaseEntity entity = builder.build(); + BaseEntity entity = builder.build(); assertEquals(names, entity.names()); } } diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BlobTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BlobTest.java index 9cd0b4ce332a..1bb7c3fc476e 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BlobTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BlobTest.java @@ -31,8 +31,8 @@ public class BlobTest { - private byte[] bytes1 = new byte[10]; - private byte[] bytes2 = new byte[11]; + private static final byte[] bytes1 = new byte[10]; + private static final byte[] bytes2 = new byte[11]; private Blob blob1; private Blob blob2; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/CursorTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/CursorTest.java index e4a9b6cbc742..72fd3d13cebe 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/CursorTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/CursorTest.java @@ -26,8 +26,8 @@ public class CursorTest { - private byte[] bytes1 = {1, 2, 3, '%', '<', '+'}; - private byte[] bytes2 = {10, 20, 30}; + private static final byte[] bytes1 = {1, 2, 3, '%', '<', '+'}; + private static final byte[] bytes2 = {10, 20, 30}; private Cursor cursor1; private Cursor cursor2; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/EntityTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/EntityTest.java index bb6d1a6eab73..30bdf16d9397 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/EntityTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/EntityTest.java @@ -16,7 +16,9 @@ package com.google.gcloud.datastore; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java index 7ed9a4e830cf..2d7f5802f247 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java @@ -140,9 +140,9 @@ public void start() throws IOException, InterruptedException { File gcdZipFile = new File(System.getProperty("java.io.tmpdir"), GCD_FILENAME); if (!gcdZipFile.exists() || !MD5_CHECKSUM.equals(md5(gcdZipFile))) { ReadableByteChannel rbc = Channels.newChannel(GCD_URL.openStream()); - FileOutputStream fos = new FileOutputStream(gcdZipFile); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); + try (FileOutputStream fos = new FileOutputStream(gcdZipFile)) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + } } // unzip the gcd try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(gcdZipFile))) { @@ -209,7 +209,7 @@ private static String md5(File gcdZipFile) throws IOException { } private static boolean isWindows() { - return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1; + return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"); } private static void extractFile(ZipInputStream zipIn, File filePath) throws IOException { diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ProjectionEntityTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ProjectionEntityTest.java index 0262fb04b89d..43eec2f02001 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ProjectionEntityTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ProjectionEntityTest.java @@ -27,7 +27,8 @@ public class ProjectionEntityTest { private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); - private static final StringValue STRING_INDEX_VALUE = StringValue.builder("foo").meaning(18).build(); + private static final StringValue STRING_INDEX_VALUE = + StringValue.builder("foo").meaning(18).build(); private static final BlobValue BLOB_VALUE = BlobValue.of(Blob.copyFrom(new byte[]{1})); private static final DateTimeValue DATE_TIME_VALUE = DateTimeValue.of(DateTime.now()); private static final LongValue LONG_INDEX_VALUE = diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java index 9574f1e246d2..5f3bfc036fa2 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java @@ -57,7 +57,8 @@ public class SerializationTest { .namespace("ns1") .build(); private static final Query GQL2 = - Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind1 where name = @name and age > @1") + Query.gqlQueryBuilder( + Query.ResultType.ENTITY, "select * from kind1 where name = @name and age > @1") .setBinding("name", "name1") .addBinding(20) .namespace("ns1") @@ -166,10 +167,10 @@ public void testValues() throws Exception { @Test public void testTypes() throws Exception { - Serializable[] types = { KEY1, KEY2, INCOMPLETE_KEY1, INCOMPLETE_KEY2, ENTITY1, ENTITY2, + Serializable[] types = { KEY1, KEY2, INCOMPLETE_KEY1, INCOMPLETE_KEY2, ENTITY1, ENTITY2, ENTITY3, EMBEDDED_ENTITY, PROJECTION_ENTITY, DATE_TIME1, BLOB1, CURSOR1, GQL1, GQL2, QUERY1, QUERY2, QUERY3}; - for (Serializable obj : types) { + for (Serializable obj : types) { Object copy = serializeAndDeserialize(obj); assertEquals(obj, obj); assertEquals(obj, copy); @@ -178,7 +179,6 @@ public void testTypes() throws Exception { } } - @SuppressWarnings("unchecked") private T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -187,7 +187,9 @@ private T serializeAndDeserialize(T obj) } try (ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { - return (T) input.readObject(); + @SuppressWarnings("unchecked") + T result = (T) input.readObject(); + return result; } } } diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java index bbfb790b69a2..973a3c3c0da4 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java @@ -81,6 +81,7 @@ public void setUp() throws Exception { ImmutableMap.Builder> builder = ImmutableMap.builder(); for (ValueType valueType : ValueType.values()) { Object[] values = TYPES.get(valueType); + @SuppressWarnings("unchecked") Class> valueClass = (Class>) values[0]; Object value = values[1]; if (value == null) { diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java index 9188117e4327..c707e6686707 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java @@ -171,9 +171,6 @@ public String getRequiredParams() { } public static void main(String... args) { - DatastoreAction action = null; - Datastore datastore = null; - Key key = null; String projectId = args.length > 0 ? args[0] : null; // If you want to access a local Datastore running via the gcd sdk, do // DatastoreOptions options = DatastoreOptions.builder() @@ -186,11 +183,11 @@ public static void main(String... args) { .namespace(NAMESPACE) .build(); String name = args.length > 1 ? args[1] : System.getProperty("user.name"); - datastore = DatastoreFactory.instance().get(options); + Datastore datastore = DatastoreFactory.instance().get(options); KeyFactory keyFactory = datastore.newKeyFactory().kind(USER_KIND); - key = keyFactory.newKey(name); + Key key = keyFactory.newKey(name); String actionName = args.length > 2 ? args[2].toLowerCase() : DEFAULT_ACTION; - action = ACTIONS.get(actionName); + DatastoreAction action = ACTIONS.get(actionName); if (action == null) { StringBuilder actionAndParams = new StringBuilder(); for (Map.Entry entry : ACTIONS.entrySet()) { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java index d77bb1eaef02..e5e319b39164 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java @@ -182,7 +182,7 @@ public static final class Project extends Entity { private final ProjectRole pRole; private final String projectId; - enum ProjectRole { + public enum ProjectRole { OWNERS, EDITORS, VIEWERS } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java index 45aa1674b03c..02b1ca966622 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java @@ -37,7 +37,7 @@ public final class BatchResponse implements Serializable { public static class Result implements Serializable { private static final long serialVersionUID = -1946539570170529094L; - private static final Result EMPTY = new BatchResponse.Result(null); + private static final Result EMPTY = Result.of(null); private final T value; private final StorageException exception; @@ -106,9 +106,10 @@ public String toString() { .toString(); } - @SuppressWarnings("unchecked") static Result empty() { - return EMPTY; + @SuppressWarnings("unchecked") + Result result = (Result) EMPTY; + return result; } } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java index 27cd807f043f..1eefe87702e6 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriterChannelImpl.java @@ -50,7 +50,7 @@ class BlobWriterChannelImpl implements BlobWriteChannel { private transient StorageRpc storageRpc; private transient StorageObject storageObject; - public BlobWriterChannelImpl(StorageOptions options, BlobInfo blobInfo, + BlobWriterChannelImpl(StorageOptions options, BlobInfo blobInfo, Map optionsMap) { this.options = options; this.blobInfo = blobInfo; diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java index 60926e01dbb2..437ce1a142d5 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java @@ -46,7 +46,8 @@ /** * A Google Storage bucket. * - * @see Concepts and Terminology + * @see Concepts and + * Terminology */ public final class BucketInfo implements Serializable { @@ -169,6 +170,7 @@ public int daysToLive() { return daysToLive; } + @Override void populateCondition(Rule.Condition condition) { condition.setAge(daysToLive); } @@ -185,6 +187,7 @@ static class RawDeleteRule extends DeleteRule { this.rule = rule; } + @Override void populateCondition(Rule.Condition condition) { throw new UnsupportedOperationException(); } @@ -219,6 +222,7 @@ public long timeMillis() { return timeMillis; } + @Override void populateCondition(Rule.Condition condition) { condition.setCreatedBefore(new DateTime(timeMillis)); } @@ -238,6 +242,7 @@ public int numNewerVersions() { return numNewerVersions; } + @Override void populateCondition(Rule.Condition condition) { condition.setNumNewerVersions(numNewerVersions); } @@ -257,6 +262,7 @@ public boolean isLive() { return isLive; } + @Override void populateCondition(Rule.Condition condition) { condition.setIsLive(isLive); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java index f9319f903760..267226c5535f 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java @@ -33,7 +33,7 @@ public final class ListResult implements Iterable, Se private final Iterable results; private final NextPageFetcher pageFetcher; - interface NextPageFetcher extends Serializable { + public interface NextPageFetcher extends Serializable { ListResult nextPage(); } 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 6427bfaccf58..e3cfbc195860 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 @@ -266,7 +266,8 @@ public static SignUrlOption withMd5() { * Service account credentials which are used for signing the URL. * If not provided an attempt will be made to get it from the environment. * - * @see Service account + * @see Service + * account */ public static SignUrlOption serviceAccount(ServiceAccountAuthCredentials credentials) { return new SignUrlOption(Option.SERVICE_ACCOUNT_CRED, credentials); 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 9e4ba2b72407..40b495bc4b47 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 @@ -104,7 +104,7 @@ public boolean equals(Object obj) { return false; } StorageOptions other = (StorageOptions) obj; - return isEquals(other) && Objects.equals(pathDelimiter, other.pathDelimiter); + return baseEquals(other) && Objects.equals(pathDelimiter, other.pathDelimiter); } public static StorageOptions defaultInstance() { diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ListResultTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ListResultTest.java index 8a2e69d0c084..c64bc0f98324 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ListResultTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ListResultTest.java @@ -31,14 +31,14 @@ public void testListResult() throws Exception { ImmutableList values = ImmutableList.of("1", "2"); final ListResult nextResult = new ListResult<>(null, "c", Collections.emptyList()); - ListResult.NextPageFetcher fetcher = new ListResult.NextPageFetcher() { + ListResult.NextPageFetcher fetcher = new ListResult.NextPageFetcher() { @Override - public ListResult nextPage() { + public ListResult nextPage() { return nextResult; } }; - ListResult result = new ListResult(fetcher, "c", values); + ListResult result = new ListResult<>(fetcher, "c", values); assertEquals(nextResult, result.nextPage()); assertEquals("c", result.nextPageCursor()); assertEquals(values, ImmutableList.copyOf(result.iterator())); diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java index e79163da3a7e..81342e4b5748 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java @@ -52,17 +52,17 @@ public class SerializationTest { Collections.>emptyList()); private static final ListResult LIST_RESULT = new ListResult<>(null, "c", Collections.singletonList(BlobInfo.of("b", "n"))); - private static Storage.BlobListOption BLOB_LIST_OPTIONS = + private static final Storage.BlobListOption BLOB_LIST_OPTIONS = Storage.BlobListOption.maxResults(100); - private static Storage.BlobSourceOption BLOB_SOURCE_OPTIONS = + private static final Storage.BlobSourceOption BLOB_SOURCE_OPTIONS = Storage.BlobSourceOption.generationMatch(1); - private static Storage.BlobTargetOption BLOB_TARGET_OPTIONS = + private static final Storage.BlobTargetOption BLOB_TARGET_OPTIONS = Storage.BlobTargetOption.generationMatch(); - private static Storage.BucketListOption BUCKET_LIST_OPTIONS = + private static final Storage.BucketListOption BUCKET_LIST_OPTIONS = Storage.BucketListOption.prefix("bla"); - private static Storage.BucketSourceOption BUCKET_SOURCE_OPTIONS = + private static final Storage.BucketSourceOption BUCKET_SOURCE_OPTIONS = Storage.BucketSourceOption.metagenerationMatch(1); - private static Storage.BucketTargetOption BUCKET_TARGET_OPTIONS = + private static final Storage.BucketTargetOption BUCKET_TARGET_OPTIONS = Storage.BucketTargetOption.metagenerationNotMatch(); @Test diff --git a/src/main/java/com/google/gcloud/storage/HttpMethod.java b/src/main/java/com/google/gcloud/storage/HttpMethod.java deleted file mode 100644 index f5889aedae90..000000000000 --- a/src/main/java/com/google/gcloud/storage/HttpMethod.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gcloud.storage; - -/** - * - */ -public enum HttpMethod { - GET, HEAD, PUT, POST, DELETE -}