Skip to content

Commit

Permalink
Clean up inspection warnings (#12)
Browse files Browse the repository at this point in the history
* Clean up warnings

* Refactor
  • Loading branch information
lwj5 authored Sep 1, 2020
1 parent 917a803 commit db2ac43
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 121 deletions.
6 changes: 3 additions & 3 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="FileLength"/>
<module name="LineLength">
<property name="max" value="120"/>
</module>

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
Expand Down Expand Up @@ -133,9 +136,6 @@

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber">
<property name="max" value="8"/>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
Expand Down Expand Up @@ -189,7 +189,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<executions>
<execution>
<id>validate</id>
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/ai/preferred/venom/fetcher/AsyncFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,6 @@ public final class AsyncFetcher implements Fetcher {
*/
private final boolean compressed;

/**
* Creates {@link BasicFuture} and fails the request with a specified exception.
*
* @param callback request callback
* @param ex specified exeption
* @return BasicFuture created
*/
private static Future<Response> failRequest(final FutureCallback<Response> callback, final Exception ex) {
final BasicFuture<Response> f = new BasicFuture<>(callback);
f.failed(ex);
return f;
}

/**
* Creates {@link BasicFuture} and cancels the request.
*
* @param callback request callback
* @return BasicFuture created
*/
private static Future<Response> cancelRequest(final FutureCallback<Response> callback) {
final BasicFuture<Response> f = new BasicFuture<>(callback);
f.cancel(true);
return f;
}

/**
* Constructs an instance of AsyncFetcher.
*
Expand Down Expand Up @@ -242,6 +217,31 @@ private AsyncFetcher(final Builder builder) {
httpClient = clientBuilder.build();
}

/**
* Creates {@link BasicFuture} and fails the request with a specified exception.
*
* @param callback request callback
* @param ex specified exception
* @return BasicFuture created
*/
private static Future<Response> failRequest(final FutureCallback<Response> callback, final Exception ex) {
final BasicFuture<Response> f = new BasicFuture<>(callback);
f.failed(ex);
return f;
}

/**
* Creates {@link BasicFuture} and cancels the request.
*
* @param callback request callback
* @return BasicFuture created
*/
private static Future<Response> cancelRequest(final FutureCallback<Response> callback) {
final BasicFuture<Response> f = new BasicFuture<>(callback);
f.cancel(true);
return f;
}

/**
* Create an instance of AsyncFetcher with default options.
*
Expand Down Expand Up @@ -467,7 +467,7 @@ public static final class Builder {
/**
* The file manager used to store raw responses.
*/
private FileManager fileManager;
private FileManager<?> fileManager;

/**
* A list of headers to append to request.
Expand Down Expand Up @@ -623,7 +623,7 @@ public Builder disableCookies() {
* @param fileManager file manager to be used.
* @return this
*/
public Builder setFileManager(final FileManager fileManager) {
public Builder setFileManager(final FileManager<?> fileManager) {
this.fileManager = fileManager;
return this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ai/preferred/venom/fetcher/StorageFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class StorageFetcher implements Fetcher {
/**
* The file manager used to store raw responses.
*/
private final FileManager fileManager;
private final FileManager<?> fileManager;

/**
* The validator used.
Expand Down Expand Up @@ -85,7 +85,7 @@ private StorageFetcher(final Builder builder) {
* @param fileManager the file manager to use.
* @return A new instance of builder
*/
public static Builder builder(final FileManager fileManager) {
public static Builder builder(final FileManager<?> fileManager) {
return new Builder(fileManager);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public void cancelled() {
});

try {
final Record record = fileManager.get(storageFetcherRequest);
final Record<?> record = fileManager.get(storageFetcherRequest);
if (record == null) {
future.cancel();
LOGGER.info("No content found from storage for: {}", request.getUrl());
Expand Down Expand Up @@ -185,7 +185,7 @@ public static final class Builder {
/**
* The file manager used to store raw responses.
*/
private final FileManager fileManager;
private final FileManager<?> fileManager;

/**
* A list of headers to append to request.
Expand All @@ -202,7 +202,7 @@ public static final class Builder {
*
* @param fileManager an instance file manager used to store raw responses.
*/
private Builder(final FileManager fileManager) {
private Builder(final FileManager<?> fileManager) {
this.fileManager = fileManager;
headers = Collections.emptyMap();
validator = new PipelineValidator(
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/ai/preferred/venom/request/VRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ private VRequest(final Method method, final String url, final Map<String, String
* @param url Request url
* @return A new instance of builder
*/
public static Builder build(final Method method, final String url) {
return new Builder(method, url);
public static Builder<?> build(final Method method, final String url) {
return new Builder<>(method, url);
}

@Override
Expand Down Expand Up @@ -201,8 +201,8 @@ protected Builder(final Method method, final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder get(final String url) {
return new Builder(Method.GET, url);
public static Builder<?> get(final String url) {
return new Builder<>(Method.GET, url);
}

/**
Expand All @@ -211,8 +211,8 @@ public static Builder get(final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder post(final String url) {
return new Builder(Method.POST, url);
public static Builder<?> post(final String url) {
return new Builder<>(Method.POST, url);
}

/**
Expand All @@ -221,8 +221,8 @@ public static Builder post(final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder head(final String url) {
return new Builder(Method.HEAD, url);
public static Builder<?> head(final String url) {
return new Builder<>(Method.HEAD, url);
}

/**
Expand All @@ -231,8 +231,8 @@ public static Builder head(final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder put(final String url) {
return new Builder(Method.PUT, url);
public static Builder<?> put(final String url) {
return new Builder<>(Method.PUT, url);
}

/**
Expand All @@ -241,8 +241,8 @@ public static Builder put(final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder delete(final String url) {
return new Builder(Method.DELETE, url);
public static Builder<?> delete(final String url) {
return new Builder<>(Method.DELETE, url);
}

/**
Expand All @@ -251,8 +251,8 @@ public static Builder delete(final String url) {
* @param url url to fetch.
* @return an instance of builder.
*/
public static Builder options(final String url) {
return new Builder(Method.OPTIONS, url);
public static Builder<?> options(final String url) {
return new Builder<>(Method.OPTIONS, url);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/preferred/venom/response/Retrievable.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public interface Retrievable extends Response {
*
* @return record where an archive has been saved
*/
Record getRecord();
Record<?> getRecord();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class StorageResponse implements Response, Retrievable {
/**
* The record holding this response.
*/
private final Record record;
private final Record<?> record;

/**
* The base url of this response.
Expand All @@ -43,7 +43,7 @@ public class StorageResponse implements Response, Retrievable {
* @param record record holding this response
* @param baseUrl base URL of the response
*/
public StorageResponse(final Record record, final String baseUrl) {
public StorageResponse(final Record<?> record, final String baseUrl) {
this.record = record;
this.baseUrl = baseUrl;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public final HttpHost getProxy() {
}

@Override
public final Record getRecord() {
public final Record<?> getRecord() {
return record;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Maksim Tkachenko
* @author Ween Jiann Lee
*/
public class DummyFileManager implements FileManager {
public class DummyFileManager implements FileManager<Object> {

/**
* Logger.
Expand Down Expand Up @@ -129,12 +129,12 @@ public final String put(final Request request, final Response response) throws S
}

@Override
public final Record get(final Object i) {
public final Record<Object> get(final Object i) {
throw new UnsupportedOperationException("File not found");
}

@Override
public final Record get(final Request request) {
public final Record<Object> get(final Request request) {
throw new UnsupportedOperationException("File not found");
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ai/preferred/venom/storage/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface FileManager<T> extends AutoCloseable {
* @throws StorageException throws StorageException
*/
@Nullable
Record get(T id) throws StorageException;
Record<T> get(T id) throws StorageException;

/**
* Returns latest record matching request.
Expand All @@ -74,6 +74,6 @@ public interface FileManager<T> extends AutoCloseable {
* @throws StorageException throws StorageException
*/
@NotNull
Record get(@NotNull Request request) throws StorageException;
Record<T> get(@NotNull Request request) throws StorageException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public class FileManagerCallback implements Callback {
/**
* The file manager used to store raw responses.
*/
private final FileManager fileManager;
private final FileManager<?> fileManager;

/**
* Constructs an instance of file manager callback.
*
* @param fileManager an instance of file manager used to store raw responses
*/
public FileManagerCallback(final FileManager fileManager) {
public FileManagerCallback(final FileManager<?> fileManager) {
this.fileManager = fileManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,8 @@ private StorageRecord<Integer> createRecord(final ResultSet rs) throws SQLExcept
}

LOGGER.debug("Record found for request: {}", rs.getString("url"));
//noinspection unchecked
return StorageRecord.builder()
.setId(rs.getInt("id"))

return StorageRecord.builder(rs.getInt("id"))
.setUrl(rs.getString("url"))
.setRequestMethod(Request.Method.valueOf(rs.getString("method")))
.setRequestHeaders(requestHeaders)
Expand Down Expand Up @@ -511,7 +510,7 @@ public static final class CompletedThreadedCallback implements Callback {
*
* @param fileManager an instance of file manager used to store raw responses.
*/
private CompletedThreadedCallback(final FileManager fileManager) {
private CompletedThreadedCallback(final FileManager<?> fileManager) {
this.fileManagerCallback = new FileManagerCallback(fileManager);
this.executorService = Executors.newCachedThreadPool(
new ThreadFactoryBuilder().setNameFormat("FileManager I/O %d").build());
Expand Down
Loading

0 comments on commit db2ac43

Please sign in to comment.