Skip to content

Commit

Permalink
Merge pull request #446 from ajkannan/fix-checkstyle-errors
Browse files Browse the repository at this point in the history
Fix checkstyle issues and warnings
  • Loading branch information
aozarov committed Dec 10, 2015
2 parents c920387 + d0eec71 commit 21d985c
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public PageImpl(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> resul

@Override
public Iterable<T> values() {
return results == null ? Collections.EMPTY_LIST : results;
return results == null ? Collections.<T>emptyList() : results;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Implementation must provide a public no-arg constructor.
* Loading of a factory implementation is done via {@link java.util.ServiceLoader}.
*/
@SuppressWarnings("rawtypes")
public interface ServiceFactory<ServiceT extends Service, ServiceOptionsT extends ServiceOptions> {

ServiceT create(ServiceOptionsT serviceOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class ServiceOptions<
ServiceT extends Service,
ServiceRpcT,
OptionsT extends ServiceOptions<ServiceT, ServiceRpcT, OptionsT>>
implements Serializable {
public abstract class ServiceOptions<ServiceT extends Service<OptionsT>, ServiceRpcT,
OptionsT extends ServiceOptions<ServiceT, ServiceRpcT, OptionsT>> implements Serializable {

private static final String DEFAULT_HOST = "https://www.googleapis.com";
private static final long serialVersionUID = 1203687993961393350L;
Expand Down Expand Up @@ -153,9 +150,7 @@ private Object readResolve() throws ObjectStreamException {
}
}

protected abstract static class Builder<
ServiceT extends Service,
ServiceRpcT,
protected abstract static class Builder<ServiceT extends Service<OptionsT>, ServiceRpcT,
OptionsT extends ServiceOptions<ServiceT, ServiceRpcT, OptionsT>,
B extends Builder<ServiceT, ServiceRpcT, OptionsT, B>> {

Expand Down Expand Up @@ -305,8 +300,8 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
if (projectIdRequired()) {
checkArgument(
projectId != null,
"A project ID is required for this service but could not be determined from the builder or "
+ "the environment. Please set a project ID using the builder.");
"A project ID is required for this service but could not be determined from the builder "
+ "or the environment. Please set a project ID using the builder.");
}
host = firstNonNull(builder.host, defaultHost());
httpTransportFactory = firstNonNull(builder.httpTransportFactory,
Expand Down Expand Up @@ -453,13 +448,15 @@ protected static String getAppEngineProjectId() {
}
}

@SuppressWarnings("unchecked")
public ServiceT service() {
if (service == null) {
service = serviceFactory.create((OptionsT) this);
}
return service;
}

@SuppressWarnings("unchecked")
public ServiceRpcT rpc() {
if (rpc == null) {
rpc = serviceRpcFactory.create((OptionsT) this);
Expand Down Expand Up @@ -587,6 +584,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou
authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null;
}

@SuppressWarnings("unchecked")
private static <T> T newInstance(String className) throws IOException, ClassNotFoundException {
try {
return (T) Class.forName(className).newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Implementation must provide a public no-arg constructor.
* Loading of a factory implementation is done via {@link java.util.ServiceLoader}.
*/
@SuppressWarnings("rawtypes")
public interface ServiceRpcFactory<ServiceRpcT, OptionsT extends ServiceOptions> {

ServiceRpcT create(OptionsT options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.junit.Test;

import java.util.Collections;

public class PageImplTest {

private static final ImmutableList<String> VALUES = ImmutableList.of("1", "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static DatastoreException translateAndThrow(DatastoreRpcException exception) {
* @throws DatastoreException every time
*/
static DatastoreException throwInvalidRequest(String massage, Object... params) {
throw new DatastoreException(DatastoreError.FAILED_PRECONDITION, String.format(massage, params));
throw new DatastoreException(
DatastoreError.FAILED_PRECONDITION, String.format(massage, params));
}

static DatastoreException propagateUserException(Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ protected String defaultProject() {
return projectId != null ? projectId : super.defaultProject();
}

@SuppressWarnings("unchecked")
@Override
protected DatastoreFactory defaultServiceFactory() {
return DefaultDatastoreFactory.INSTANCE;
}

@SuppressWarnings("unchecked")
@Override
protected DatastoreRpcFactory defaultRpcFactory() {
return DefaultDatastoreRpcFactory.INSTANCE;
Expand Down Expand Up @@ -199,6 +201,7 @@ protected Set<String> scopes() {
return SCOPES;
}

@SuppressWarnings("unchecked")
@Override
public Builder toBuilder() {
return new Builder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class DatastoreOptionsTest {

private static final String PROJECT_ID = "project_id";
Expand All @@ -41,7 +39,7 @@ public class DatastoreOptionsTest {
private DatastoreOptions.Builder options;

@Before
public void setUp() throws IOException, InterruptedException {
public void setUp() {
datastoreRpcFactory = EasyMock.createMock(DatastoreRpcFactory.class);
datastoreRpc = EasyMock.createMock(DatastoreRpc.class);
options = DatastoreOptions.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void beforeClass() throws IOException, InterruptedException {
}

@Before
public void setUp() throws IOException, InterruptedException {
public void setUp() {
options = DatastoreOptions.builder()
.projectId(PROJECT_ID)
.host("http://localhost:" + PORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public class ValueTest {

private ImmutableMap<ValueType, Value<?>> typeToValue;

@SuppressWarnings("rawtypes")
private class TestBuilder extends Value.BaseBuilder<Set, Value<Set>, TestBuilder> {
TestBuilder() {
super(ValueType.LIST);
}

@SuppressWarnings({"unchecked"})
@Override
public Value<Set> build() {
return new Value(this) {
Expand Down Expand Up @@ -197,6 +199,7 @@ public void testGet() throws Exception {
@Test
public void testToBuilder() throws Exception {
Set<String> content = Collections.singleton("bla");
@SuppressWarnings("rawtypes")
ValueBuilder builder = new TestBuilder();
builder.meaning(1).set(content).indexed(true);
Value<?> value = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import com.google.gcloud.storage.BlobId;
import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.storage.BlobReadChannel;
import com.google.gcloud.storage.CopyWriter;
import com.google.gcloud.storage.BlobWriteChannel;
import com.google.gcloud.storage.Bucket;
import com.google.gcloud.storage.BucketInfo;
import com.google.gcloud.storage.CopyWriter;
import com.google.gcloud.storage.Storage;
import com.google.gcloud.storage.Storage.ComposeRequest;
import com.google.gcloud.storage.Storage.CopyRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ public BatchResponse batch(BatchRequest request) throws StorageException {
List<List<Tuple<StorageObject, Map<Option, ?>>>> partitionedToDelete =
Lists.partition(request.toDelete, MAX_BATCH_DELETES);
Iterator<List<Tuple<StorageObject, Map<Option, ?>>>> iterator = partitionedToDelete.iterator();
BatchRequest chunkRequest = new BatchRequest(iterator.hasNext() ? iterator.next() :
ImmutableList.<Tuple<StorageObject, Map<Option, ?>>>of(), request.toUpdate, request.toGet);
BatchRequest chunkRequest = new BatchRequest(
iterator.hasNext()
? iterator.next() : ImmutableList.<Tuple<StorageObject, Map<Option, ?>>>of(),
request.toUpdate, request.toGet);
BatchResponse response = batchChunk(chunkRequest);
Map<StorageObject, Tuple<Boolean, StorageException>> deletes =
Maps.newHashMapWithExpectedSize(request.toDelete.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions;
import static com.google.gcloud.storage.Blob.BlobSourceOption.toGetOptions;
import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
*/
class BlobWriteChannelImpl implements BlobWriteChannel {

private static final long serialVersionUID = 8675286882724938737L;
private static final int MIN_CHUNK_SIZE = 256 * 1024;
private static final int DEFAULT_CHUNK_SIZE = 8 * MIN_CHUNK_SIZE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Iterators;
import com.google.gcloud.PageImpl;
import com.google.gcloud.Page;
import com.google.gcloud.PageImpl;
import com.google.gcloud.spi.StorageRpc;
import com.google.gcloud.storage.Storage.BlobGetOption;
import com.google.gcloud.storage.Storage.BlobTargetOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void readObject(ObjectInputStream in) throws IOException,
rule = new JacksonFactory().fromString(in.readUTF(), Rule.class);
}

@Override
Rule toPb() {
return rule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
import com.google.gcloud.Service;
import com.google.gcloud.Page;
import com.google.gcloud.Service;
import com.google.gcloud.spi.StorageRpc;
import com.google.gcloud.spi.StorageRpc.Tuple;

import java.io.InputStream;
import java.io.Serializable;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ private <I, O extends Serializable> List<BatchResponse.Result<O>> transformBatch
if (exception != null) {
response.add(new BatchResponse.Result<O>(exception));
} else {
response.add(object != null ?
BatchResponse.Result.of(transform.apply(object)) : BatchResponse.Result.<O>empty());
response.add(object != null
? BatchResponse.Result.of(transform.apply(object)) : BatchResponse.Result.<O>empty());
}
}
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ private StorageOptions(Builder builder) {
pathDelimiter = MoreObjects.firstNonNull(builder.pathDelimiter, DEFAULT_PATH_DELIMITER);
}

@SuppressWarnings("unchecked")
@Override
protected StorageFactory defaultServiceFactory() {
return DefaultStorageFactory.INSTANCE;
}

@SuppressWarnings("unchecked")
@Override
protected StorageRpcFactory defaultRpcFactory() {
return DefaultStorageRpcFactory.INSTANCE;
Expand All @@ -118,6 +120,7 @@ public static StorageOptions defaultInstance() {
return builder().build();
}

@SuppressWarnings("unchecked")
@Override
public Builder toBuilder() {
return new Builder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class BlobReadChannelImplTest {
private BlobReadChannelImpl reader;

@Before
public void setUp() throws IOException, InterruptedException {
public void setUp() {
rpcFactoryMock = createMock(StorageRpcFactory.class);
storageRpcMock = createMock(StorageRpc.class);
expect(rpcFactoryMock.create(anyObject(StorageOptions.class))).andReturn(storageRpcMock);
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testSeek() throws IOException {
}

@Test
public void testClose() throws IOException {
public void testClose() {
replay(storageRpcMock);
reader = new BlobReadChannelImpl(options, BLOB_ID, EMPTY_RPC_OPTIONS);
assertTrue(reader.isOpen());
Expand Down Expand Up @@ -176,9 +176,9 @@ public void testReadGenerationChanged() throws IOException {
ByteBuffer secondReadBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE);
expect(storageRpcMock.read(blobId.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE))
.andReturn(StorageRpc.Tuple.of("etag1", firstResult));
expect(storageRpcMock.read(
blobId.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE, DEFAULT_CHUNK_SIZE))
.andReturn(StorageRpc.Tuple.of("etag2", firstResult));
expect(
storageRpcMock.read(blobId.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE,
DEFAULT_CHUNK_SIZE)).andReturn(StorageRpc.Tuple.of("etag2", secondResult));
replay(storageRpcMock);
reader.read(firstReadBuffer);
try {
Expand All @@ -192,7 +192,7 @@ public void testReadGenerationChanged() throws IOException {
}

@Test
public void testSaveAndRestore() throws IOException, ClassNotFoundException {
public void testSaveAndRestore() throws IOException {
byte[] firstResult = randomByteArray(DEFAULT_CHUNK_SIZE);
byte[] secondResult = randomByteArray(DEFAULT_CHUNK_SIZE);
ByteBuffer firstReadBuffer = ByteBuffer.allocate(42);
Expand All @@ -216,6 +216,7 @@ public void testSaveAndRestore() throws IOException, ClassNotFoundException {
public void testStateEquals() {
replay(storageRpcMock);
reader = new BlobReadChannelImpl(options, BLOB_ID, EMPTY_RPC_OPTIONS);
@SuppressWarnings("resource") // avoid closing when you don't want partial writes to GCS
BlobReadChannel secondReader = new BlobReadChannelImpl(options, BLOB_ID, EMPTY_RPC_OPTIONS);
RestorableState<BlobReadChannel> state = reader.capture();
RestorableState<BlobReadChannel> secondState = secondReader.capture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void testCopyTo() throws Exception {
public void testCopyToBlobId() throws Exception {
BlobId targetId = BlobId.of("bt", "nt");
CopyWriter copyWriter = createMock(CopyWriter.class);
BlobInfo target = BLOB_INFO.builder(targetId).build();
BlobInfo target = BlobInfo.builder(targetId).build();
Capture<CopyRequest> capturedCopyRequest = Capture.newInstance();
expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
replay(storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class BlobWriteChannelImplTest {
private BlobWriteChannelImpl writer;

@Before
public void setUp() throws IOException, InterruptedException {
public void setUp() {
rpcFactoryMock = createMock(StorageRpcFactory.class);
storageRpcMock = createMock(StorageRpc.class);
expect(rpcFactoryMock.create(anyObject(StorageOptions.class)))
Expand Down Expand Up @@ -234,6 +234,8 @@ public void testStateEquals() {
.times(2);
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
// avoid closing when you don't want partial writes to GCS upon failure
@SuppressWarnings("resource")
BlobWriteChannel writer2 = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
RestorableState<BlobWriteChannel> state = writer.capture();
RestorableState<BlobWriteChannel> state2 = writer2.capture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.gcloud.storage.Acl.Project.ProjectRole.VIEWERS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.api.services.storage.model.Bucket.Lifecycle.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.gcloud.PageImpl;
import com.google.gcloud.Page;
import com.google.gcloud.PageImpl;
import com.google.gcloud.storage.BatchResponse.Result;

import org.easymock.Capture;
Expand Down Expand Up @@ -153,8 +153,8 @@ public void testGetAll() throws Exception {
for (BlobInfo info : BLOB_INFO_RESULTS) {
batchResultList.add(new Result<>(info));
}
BatchResponse response =
new BatchResponse(Collections.EMPTY_LIST, Collections.EMPTY_LIST, batchResultList);
BatchResponse response = new BatchResponse(Collections.<Result<Boolean>>emptyList(),
Collections.<Result<BlobInfo>>emptyList(), batchResultList);
expect(storage.apply(capture(capturedBatchRequest))).andReturn(response);
replay(storage);
List<Blob> blobs = bucket.get("n1", "n2", "n3");
Expand Down
Loading

0 comments on commit 21d985c

Please sign in to comment.