Skip to content

Commit

Permalink
Style-check to enforce unused import and final variable checks
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1491511 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ok2c committed Jun 10, 2013
1 parent 69057e1 commit b1c387e
Show file tree
Hide file tree
Showing 144 changed files with 711 additions and 847 deletions.
7 changes: 0 additions & 7 deletions .pydevproject

This file was deleted.

5 changes: 2 additions & 3 deletions hc-checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
<module name="AvoidStarImport"/>
<module name="IllegalImport" />
<module name="RedundantImport" />
<module name="UnusedImports"/>
<module name="EqualsHashCode"/>
</module>
<module name="Header">
<property name="headerFile" value="asl2.header" />
</module>
<module name="FileLength">
<property name="max" value="10000" />
</module>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
Expand All @@ -43,10 +42,10 @@
import org.apache.http.util.Args;

/**
* Structure used to store an {@link HttpResponse} in a cache. Some entries
* can optionally depend on system resources that may require explicit
* deallocation. In such a case {@link #getResource()} should return a non
* null instance of {@link Resource} that must be deallocated by calling
* Structure used to store an {@link org.apache.http.HttpResponse} in a cache.
* Some entries can optionally depend on system resources that may require
* explicit deallocation. In such a case {@link #getResource()} should return
* a non null instance of {@link Resource} that must be deallocated by calling
* {@link Resource#dispose()} method when no longer used.
*
* @since 4.1
Expand Down Expand Up @@ -139,29 +138,32 @@ private Date parseDate() {
}

/**
* Returns the {@link StatusLine} from the origin {@link HttpResponse}.
* Returns the {@link StatusLine} from the origin
* {@link org.apache.http.HttpResponse}.
*/
public StatusLine getStatusLine() {
return this.statusLine;
}

/**
* Returns the {@link ProtocolVersion} from the origin {@link HttpResponse}.
* Returns the {@link ProtocolVersion} from the origin
* {@link org.apache.http.HttpResponse}.
*/
public ProtocolVersion getProtocolVersion() {
return this.statusLine.getProtocolVersion();
}

/**
* Gets the reason phrase from the origin {@link HttpResponse}, for example,
* "Not Modified".
* Gets the reason phrase from the origin
* {@link org.apache.http.HttpResponse}, for example, "Not Modified".
*/
public String getReasonPhrase() {
return this.statusLine.getReasonPhrase();
}

/**
* Returns the HTTP response code from the origin {@link HttpResponse}.
* Returns the HTTP response code from the origin
* {@link org.apache.http.HttpResponse}.
*/
public int getStatusCode() {
return this.statusLine.getStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package org.apache.http.impl.client.cache;

import java.io.IOException;
import java.util.LinkedHashMap;

import org.apache.http.annotation.ThreadSafe;
import org.apache.http.client.cache.HttpCacheEntry;
Expand All @@ -36,11 +35,11 @@

/**
* Basic {@link HttpCacheStorage} implementation backed by an instance of
* {@link LinkedHashMap}. In other words, cache entries and the cached
* response bodies are held in-memory. This cache does NOT deallocate
* resources associated with the cache entries; it is intended for use
* with {@link HeapResource} and similar. This is the default cache
* storage backend used by {@link CachingHttpClient}.
* {@link java.util.LinkedHashMap}. In other words, cache entries and
* the cached response bodies are held in-memory. This cache does NOT
* deallocate resources associated with the cache entries; it is intended
* for use with {@link HeapResource} and similar. This is the default cache
* storage backend used by {@link CachingHttpClients}.
*
* @since 4.1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

import java.util.Date;

import net.sf.ehcache.CacheEntry;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
Expand All @@ -44,7 +42,7 @@
import org.apache.http.protocol.HTTP;

/**
* Rebuilds an {@link HttpResponse} from a {@link CacheEntry}
* Rebuilds an {@link HttpResponse} from a {@link net.sf.ehcache.CacheEntry}
*
* @since 4.1
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolException;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.cache.HeaderConstants;
Expand All @@ -45,8 +44,9 @@ class ConditionalRequestBuilder {

/**
* When a {@link HttpCacheEntry} is stale but 'might' be used as a response
* to an {@link HttpRequest} we will attempt to revalidate the entry with
* the origin. Build the origin {@link HttpRequest} here and return it.
* to an {@link org.apache.http.HttpRequest} we will attempt to revalidate
* the entry with the origin. Build the origin {@link org.apache.http.HttpRequest}
* here and return it.
*
* @param request the original request from the caller
* @param cacheEntry the entry that needs to be re-validated
Expand Down Expand Up @@ -83,10 +83,11 @@ public HttpRequestWrapper buildConditionalRequest(final HttpRequestWrapper reque
}

/**
* When a {@link HttpCacheEntry} does not exist for a specific {@link HttpRequest}
* we attempt to see if an existing {@link HttpCacheEntry} is appropriate by building
* a conditional {@link HttpRequest} using the variants' ETag values. If no such values
* exist, the request is unmodified
* When a {@link HttpCacheEntry} does not exist for a specific
* {@link org.apache.http.HttpRequest} we attempt to see if an existing
* {@link HttpCacheEntry} is appropriate by building a conditional
* {@link org.apache.http.HttpRequest} using the variants' ETag values.
* If no such values exist, the request is unmodified
*
* @param request the original request from the caller
* @param variants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int getErrorCount(final String identifier) {
return storedErrorCode != null ? storedErrorCode.getErrorCount() : 0;
}

public void resetErrorCount(String identifier) {
public void resetErrorCount(final String identifier) {
if (identifier == null) {
throw new IllegalArgumentException("identifier may not be null");
}
Expand Down Expand Up @@ -106,7 +106,7 @@ private void updateValue(final String identifier) {
}
}
else {
int errorCount = oldValue.getErrorCount();
final int errorCount = oldValue.getErrorCount();
if (errorCount == Integer.MAX_VALUE) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
* @see #DEFAULT_MAX_EXPIRY_IN_MILLIS
*/
public ExponentialBackOffSchedulingStrategy(final CacheConfig cacheConfig) {
this(cacheConfig, DEFAULT_BACK_OFF_RATE, DEFAULT_INITIAL_EXPIRY_IN_MILLIS, DEFAULT_MAX_EXPIRY_IN_MILLIS);
this(cacheConfig,
DEFAULT_BACK_OFF_RATE,
DEFAULT_INITIAL_EXPIRY_IN_MILLIS,
DEFAULT_MAX_EXPIRY_IN_MILLIS);
}

/**
* Create a new scheduling strategy by using a fixed pool of worker threads and the given parameters to calculated
* the delay.
* Create a new scheduling strategy by using a fixed pool of worker threads and the
* given parameters to calculated the delay.
*
* @param cacheConfig the thread pool configuration to be used; not <code>null</code>
* @param backOffRate the back off rate to be used; not negative
Expand All @@ -90,24 +93,38 @@ public ExponentialBackOffSchedulingStrategy(final CacheConfig cacheConfig) {
* @see org.apache.http.impl.client.cache.CacheConfig#getAsynchronousWorkersMax()
* @see ExponentialBackOffSchedulingStrategy
*/
public ExponentialBackOffSchedulingStrategy(final CacheConfig cacheConfig, final long backOffRate, final long initialExpiryInMillis, final long maxExpiryInMillis) {
this(createThreadPoolFromCacheConfig(cacheConfig), backOffRate, initialExpiryInMillis, maxExpiryInMillis);
public ExponentialBackOffSchedulingStrategy(
final CacheConfig cacheConfig,
final long backOffRate,
final long initialExpiryInMillis,
final long maxExpiryInMillis) {
this(createThreadPoolFromCacheConfig(cacheConfig),
backOffRate,
initialExpiryInMillis,
maxExpiryInMillis);
}

private static ScheduledThreadPoolExecutor createThreadPoolFromCacheConfig(final CacheConfig cacheConfig) {
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(cacheConfig.getAsynchronousWorkersMax());
private static ScheduledThreadPoolExecutor createThreadPoolFromCacheConfig(
final CacheConfig cacheConfig) {
final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(
cacheConfig.getAsynchronousWorkersMax());
scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return scheduledThreadPoolExecutor;
}

ExponentialBackOffSchedulingStrategy(final ScheduledExecutorService executor, final long backOffRate, final long initialExpiryInMillis, final long maxExpiryInMillis) {
ExponentialBackOffSchedulingStrategy(
final ScheduledExecutorService executor,
final long backOffRate,
final long initialExpiryInMillis,
final long maxExpiryInMillis) {
this.executor = checkNotNull("executor", executor);
this.backOffRate = checkNotNegative("backOffRate", backOffRate);
this.initialExpiryInMillis = checkNotNegative("initialExpiryInMillis", initialExpiryInMillis);
this.maxExpiryInMillis = checkNotNegative("maxExpiryInMillis", maxExpiryInMillis);
}

public void schedule(final AsynchronousValidationRequest revalidationRequest) {
public void schedule(
final AsynchronousValidationRequest revalidationRequest) {
checkNotNull("revalidationRequest", revalidationRequest);
final int consecutiveFailedAttempts = revalidationRequest.getConsecutiveFailedAttempts();
final long delayInMillis = calculateDelayInMillis(consecutiveFailedAttempts);
Expand All @@ -132,7 +149,8 @@ public long getMaxExpiryInMillis() {

protected long calculateDelayInMillis(final int consecutiveFailedAttempts) {
if (consecutiveFailedAttempts > 0) {
final long delayInSeconds = (long) (initialExpiryInMillis * Math.pow(backOffRate, consecutiveFailedAttempts - 1));
final long delayInSeconds = (long) (initialExpiryInMillis *
Math.pow(backOffRate, consecutiveFailedAttempts - 1));
return Math.min(delayInSeconds, maxExpiryInMillis);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class FailureCacheValue {
private final String key;
private final int errorCount;

public FailureCacheValue(String key, int errorCount) {
public FailureCacheValue(final String key, final int errorCount) {
this.creationTimeInNanos = System.nanoTime();
this.key = key;
this.errorCount = errorCount;
Expand All @@ -61,6 +61,7 @@ public int getErrorCount() {

@Override
public String toString() {
return "[entry creationTimeInNanos=" + creationTimeInNanos + "; key=" + key + "; errorCount=" + errorCount + ']';
return "[entry creationTimeInNanos=" + creationTimeInNanos + "; " +
"key=" + key + "; errorCount=" + errorCount + ']';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Resource copy(
return createResource(body);
}

Resource createResource(byte[] buf) {
Resource createResource(final byte[] buf) {
return new HeapResource(buf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.io.Closeable;
import java.io.IOException;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -42,12 +41,13 @@

/**
* {@link HttpCacheStorage} implementation capable of deallocating resources associated with
* the cache entries. This cache keeps track of cache entries using {@link PhantomReference}
* and maintains a collection of all resources that are no longer in use. The cache, however,
* does not automatically deallocates associated resources by invoking {@link Resource#dispose()}
* method. The consumer MUST periodically call {@link #cleanResources()} method to trigger
* resource deallocation. The cache can be permanently shut down using {@link #shutdown()}
* method. All resources associated with the entries used by the cache will be deallocated.
* the cache entries. This cache keeps track of cache entries using
* {@link java.lang.ref.PhantomReference} and maintains a collection of all resources that
* are no longer in use. The cache, however, does not automatically deallocates associated
* resources by invoking {@link Resource#dispose()} method. The consumer MUST periodically
* call {@link #cleanResources()} method to trigger resource deallocation. The cache can be
* permanently shut down using {@link #shutdown()} method. All resources associated with
* the entries used by the cache will be deallocated.
*
* This {@link HttpCacheStorage} implementation is intended for use with {@link FileResource}
* and similar.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ResponseCachingPolicy {
public ResponseCachingPolicy(final long maxObjectSizeBytes,
final boolean sharedCache,
final boolean neverCache1_0ResponsesWithQueryString,
boolean allow303Caching) {
final boolean allow303Caching) {
this.maxObjectSizeBytes = maxObjectSizeBytes;
this.sharedCache = sharedCache;
this.neverCache1_0ResponsesWithQueryString = neverCache1_0ResponsesWithQueryString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@
*
*/package org.apache.http.impl.client.cache.memcached;

import org.apache.http.client.cache.HttpCacheStorage;

/**
* Since the {@link HttpCacheStorage} interface expects to use variant-annotated
* URLs for its storage keys, but Memcached has a maximum key size, we need to
* support mapping storage keys to cache keys. Clients can implement this
* interface to change the way the mapping is done (for example, to add a prefix
* to all cache keys to provide a form of memcached namespacing).
* Since the {@link org.apache.http.client.cache.HttpCacheStorage} interface
* expects to use variant-annotated URLs for its storage keys, but Memcached
* has a maximum key size, we need to support mapping storage keys to cache
* keys. Clients can implement this interface to change the way the mapping
* is done (for example, to add a prefix to all cache keys to provide a form
* of memcached namespacing).
*/
public interface KeyHashingScheme {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class TestCachingHttpClientBuilder {

@Test
public void testAsynchronousWorkersMax0() throws Exception {
CacheConfig cacheConfig = CacheConfig.custom().setAsynchronousWorkersMax(0).build();
final CacheConfig cacheConfig = CacheConfig.custom()
.setAsynchronousWorkersMax(0)
.build();
// Asynchronous validation should be disabled but we should not get an
// Exception
CachingHttpClientBuilder.create().setCacheConfig(cacheConfig).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testResetErrorCount() {
failureCache.increaseErrorCount(IDENTIFIER);
failureCache.resetErrorCount(IDENTIFIER);

int errorCount = failureCache.getErrorCount(IDENTIFIER);
final int errorCount = failureCache.getErrorCount(IDENTIFIER);
Assert.assertEquals(0, errorCount);
}

Expand All @@ -51,7 +51,7 @@ public void testIncrementErrorCount() {
failureCache.increaseErrorCount(IDENTIFIER);
failureCache.increaseErrorCount(IDENTIFIER);

int errorCount = failureCache.getErrorCount(IDENTIFIER);
final int errorCount = failureCache.getErrorCount(IDENTIFIER);
Assert.assertEquals(3, errorCount);
}

Expand All @@ -63,7 +63,7 @@ public void testMaxSize() {
failureCache.increaseErrorCount("c");
failureCache.increaseErrorCount("d");

int errorCount = failureCache.getErrorCount("a");
final int errorCount = failureCache.getErrorCount("a");
Assert.assertEquals(0, errorCount);
}
}
Loading

0 comments on commit b1c387e

Please sign in to comment.