Skip to content

Commit

Permalink
Merge pull request #18 from Ericliu001/master
Browse files Browse the repository at this point in the history
coding style
  • Loading branch information
jpd236 committed Apr 17, 2017
2 parents bc67181 + 1af9010 commit a444f81
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 52 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/android/volley/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,43 @@ public interface Cache {
* @param key Cache key
* @return An {@link Entry} or null in the event of a cache miss
*/
public Entry get(String key);
Entry get(String key);

/**
* Adds or replaces an entry to the cache.
* @param key Cache key
* @param entry Data to store and metadata for cache coherency, TTL, etc.
*/
public void put(String key, Entry entry);
void put(String key, Entry entry);

/**
* Performs any potentially long-running actions needed to initialize the cache;
* will be called from a worker thread.
*/
public void initialize();
void initialize();

/**
* Invalidates an entry in the cache.
* @param key Cache key
* @param fullExpire True to fully expire the entry, false to soft expire
*/
public void invalidate(String key, boolean fullExpire);
void invalidate(String key, boolean fullExpire);

/**
* Removes an entry from the cache.
* @param key Cache key
*/
public void remove(String key);
void remove(String key);

/**
* Empties the cache.
*/
public void clear();
void clear();

/**
* Data and metadata for an entry returned by the cache.
*/
public static class Entry {
class Entry {
/** The data returned from cache. */
public byte[] data;

Expand All @@ -87,12 +87,12 @@ public static class Entry {
public Map<String, String> responseHeaders = Collections.emptyMap();

/** True if the entry is expired. */
public boolean isExpired() {
boolean isExpired() {
return this.ttl < System.currentTimeMillis();
}

/** True if a refresh is needed from the original data source. */
public boolean refreshNeeded() {
boolean refreshNeeded() {
return this.softTtl < System.currentTimeMillis();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/android/volley/CacheDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public void run() {
if (mQuit) {
return;
}
continue;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/android/volley/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public interface Network {
* @return A {@link NetworkResponse} with data and caching metadata; will never be null
* @throws VolleyError on errors
*/
public NetworkResponse performRequest(Request<?> request) throws VolleyError;
NetworkResponse performRequest(Request<?> request) throws VolleyError;
}
28 changes: 14 additions & 14 deletions src/main/java/com/android/volley/RequestQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
public class RequestQueue {

/** Callback interface for completed requests. */
public static interface RequestFinishedListener<T> {
public interface RequestFinishedListener<T> {
/** Called when a request has finished processing. */
public void onRequestFinished(Request<T> request);
void onRequestFinished(Request<T> request);
}

/** Used for generating monotonically-increasing sequence numbers for requests. */
private AtomicInteger mSequenceGenerator = new AtomicInteger();
private final AtomicInteger mSequenceGenerator = new AtomicInteger();

/**
* Staging area for requests that already have a duplicate request in flight.
Expand All @@ -59,7 +59,7 @@ public static interface RequestFinishedListener<T> {
* </ul>
*/
private final Map<String, Queue<Request<?>>> mWaitingRequests =
new HashMap<String, Queue<Request<?>>>();
new HashMap<>();

/**
* The set of all requests currently being processed by this RequestQueue. A Request
Expand All @@ -70,11 +70,11 @@ public static interface RequestFinishedListener<T> {

/** The cache triage queue. */
private final PriorityBlockingQueue<Request<?>> mCacheQueue =
new PriorityBlockingQueue<Request<?>>();
new PriorityBlockingQueue<>();

/** The queue of requests that are actually going out to the network. */
private final PriorityBlockingQueue<Request<?>> mNetworkQueue =
new PriorityBlockingQueue<Request<?>>();
new PriorityBlockingQueue<>();

/** Number of network request dispatcher threads to start. */
private static final int DEFAULT_NETWORK_THREAD_POOL_SIZE = 4;
Expand All @@ -89,13 +89,13 @@ public static interface RequestFinishedListener<T> {
private final ResponseDelivery mDelivery;

/** The network dispatchers. */
private NetworkDispatcher[] mDispatchers;
private final NetworkDispatcher[] mDispatchers;

/** The cache dispatcher. */
private CacheDispatcher mCacheDispatcher;

private List<RequestFinishedListener> mFinishedListeners =
new ArrayList<RequestFinishedListener>();
private final List<RequestFinishedListener> mFinishedListeners =
new ArrayList<>();

/**
* Creates the worker pool. Processing will not begin until {@link #start()} is called.
Expand Down Expand Up @@ -160,9 +160,9 @@ public void stop() {
if (mCacheDispatcher != null) {
mCacheDispatcher.quit();
}
for (int i = 0; i < mDispatchers.length; i++) {
if (mDispatchers[i] != null) {
mDispatchers[i].quit();
for (final NetworkDispatcher mDispatcher : mDispatchers) {
if (mDispatcher != null) {
mDispatcher.quit();
}
}
}
Expand All @@ -186,7 +186,7 @@ public Cache getCache() {
* {@link RequestQueue#cancelAll(RequestFilter)}.
*/
public interface RequestFilter {
public boolean apply(Request<?> request);
boolean apply(Request<?> request);
}

/**
Expand Down Expand Up @@ -248,7 +248,7 @@ public <T> Request<T> add(Request<T> request) {
// There is already a request in flight. Queue up.
Queue<Request<?>> stagedRequests = mWaitingRequests.get(cacheKey);
if (stagedRequests == null) {
stagedRequests = new LinkedList<Request<?>>();
stagedRequests = new LinkedList<>();
}
stagedRequests.add(request);
mWaitingRequests.put(cacheKey, stagedRequests);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/android/volley/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Response<T> {
/** Callback interface for delivering parsed responses. */
public interface Listener<T> {
/** Called when a response is received. */
public void onResponse(T response);
void onResponse(T response);
}

/** Callback interface for delivering error responses. */
Expand All @@ -35,7 +35,7 @@ public interface ErrorListener {
* Callback method that an error has been occurred with the
* provided error code and optional user-readable message.
*/
public void onErrorResponse(VolleyError error);
void onErrorResponse(VolleyError error);
}

/** Returns a successful response containing the parsed result. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/android/volley/ResponseDelivery.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public interface ResponseDelivery {
/**
* Parses a response from the network or cache and delivers it.
*/
public void postResponse(Request<?> request, Response<?> response);
void postResponse(Request<?> request, Response<?> response);

/**
* Parses a response from the network or cache and delivers it. The provided
* Runnable will be executed after delivery.
*/
public void postResponse(Request<?> request, Response<?> response, Runnable runnable);
void postResponse(Request<?> request, Response<?> response, Runnable runnable);

/**
* Posts an error for the given request.
*/
public void postError(Request<?> request, VolleyError error);
void postError(Request<?> request, VolleyError error);
}
6 changes: 3 additions & 3 deletions src/main/java/com/android/volley/RetryPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public interface RetryPolicy {
/**
* Returns the current timeout (used for logging).
*/
public int getCurrentTimeout();
int getCurrentTimeout();

/**
* Returns the current retry count (used for logging).
*/
public int getCurrentRetryCount();
int getCurrentRetryCount();

/**
* Prepares for the next retry by applying a backoff to the timeout.
* @param error The error code of the last attempt.
* @throws VolleyError In the event that the retry could not be performed (for example if we
* ran out of attempts), the passed in error is thrown.
*/
public void retry(VolleyError error) throws VolleyError;
void retry(VolleyError error) throws VolleyError;
}
4 changes: 2 additions & 2 deletions src/main/java/com/android/volley/toolbox/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public interface Authenticator {
*
* @throws AuthFailureError If authentication did not succeed
*/
public String getAuthToken() throws AuthFailureError;
String getAuthToken() throws AuthFailureError;

/**
* Invalidates the provided auth token.
*/
public void invalidateAuthToken(String authToken);
void invalidateAuthToken(String authToken);
}
6 changes: 3 additions & 3 deletions src/main/java/com/android/volley/toolbox/BasicNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
public class BasicNetwork implements Network {
protected static final boolean DEBUG = VolleyLog.DEBUG;

private static int SLOW_REQUEST_THRESHOLD_MS = 3000;
private static final int SLOW_REQUEST_THRESHOLD_MS = 3000;

private static int DEFAULT_POOL_SIZE = 4096;
private static final int DEFAULT_POOL_SIZE = 4096;

protected final HttpStack mHttpStack;

Expand Down Expand Up @@ -257,7 +257,7 @@ private byte[] entityToBytes(HttpEntity entity) throws IOException, ServerError
} catch (IOException e) {
// This can happen if there was an exception above that left the entity in
// an invalid state.
VolleyLog.v("Error occured when calling consumingContent");
VolleyLog.v("Error occurred when calling consumingContent");
}
mPool.returnBuf(buffer);
bytes.close();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/android/volley/toolbox/ByteArrayPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
*/
public class ByteArrayPool {
/** The buffer pool, arranged both by last use and by buffer size */
private List<byte[]> mBuffersByLastUse = new LinkedList<byte[]>();
private List<byte[]> mBuffersBySize = new ArrayList<byte[]>(64);
private final List<byte[]> mBuffersByLastUse = new LinkedList<byte[]>();
private final List<byte[]> mBuffersBySize = new ArrayList<byte[]>(64);

/** The total size of the buffers in the pool */
private int mCurrentSize = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/android/volley/toolbox/HttpStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface HttpStack {
* {@link Request#getHeaders()}
* @return the HTTP response
*/
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
throws IOException, AuthFailureError;

}
2 changes: 1 addition & 1 deletion src/main/java/com/android/volley/toolbox/HurlStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface UrlRewriter {
* Returns a URL to use instead of the provided one, or null to indicate
* this URL should not be used at all.
*/
public String rewriteUrl(String originalUrl);
String rewriteUrl(String originalUrl);
}

private final UrlRewriter mUrlRewriter;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/android/volley/toolbox/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public class ImageLoader {
* must not block. Implementation with an LruCache is recommended.
*/
public interface ImageCache {
public Bitmap getBitmap(String url);
public void putBitmap(String url, Bitmap bitmap);
Bitmap getBitmap(String url);
void putBitmap(String url, Bitmap bitmap);
}

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ public interface ImageListener extends ErrorListener {
* image loading in order to, for example, run an animation to fade in network loaded
* images.
*/
public void onResponse(ImageContainer response, boolean isImmediate);
void onResponse(ImageContainer response, boolean isImmediate);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/android/volley/toolbox/ImageRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ImageRequest extends Request<Bitmap> {
private final Config mDecodeConfig;
private final int mMaxWidth;
private final int mMaxHeight;
private ScaleType mScaleType;
private final ScaleType mScaleType;

/** Decoding lock so that we don't decode more than one image at a time (to avoid OOM's) */
private static final Object sDecodeLock = new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ void loadImageIfNecessary(final boolean isInLayoutPass) {

// The pre-existing content of this view didn't match the current URL. Load the new image
// from the network.
ImageContainer newContainer = mImageLoader.get(mUrl,

// update the ImageContainer to be the new bitmap container.
mImageContainer = mImageLoader.get(mUrl,
new ImageListener() {
@Override
public void onErrorResponse(VolleyError error) {
Expand Down Expand Up @@ -179,9 +181,6 @@ public void run() {
}
}
}, maxWidth, maxHeight, scaleType);

// update the ImageContainer to be the new bitmap container.
mImageContainer = newContainer;
}

private void setDefaultImageOrNull() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/android/volley/mock/TestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public DeprecatedGet() {

/** Test example of a POST request in the deprecated style. */
public static class DeprecatedPost extends Base {
private Map<String, String> mPostParams;
private final Map<String, String> mPostParams;

public DeprecatedPost() {
super(TEST_URL, null);
Expand Down Expand Up @@ -89,7 +89,7 @@ public Post() {

/** Test example of a POST request in the new style with a body. */
public static class PostWithBody extends Post {
private Map<String, String> mParams;
private final Map<String, String> mParams;

public PostWithBody() {
mParams = new HashMap<String, String>();
Expand Down

0 comments on commit a444f81

Please sign in to comment.