Skip to content

Commit

Permalink
Merge pull request #15 from DevFactory/release/general-code-quality-f…
Browse files Browse the repository at this point in the history
…ix-3

General code quality fix-3
  • Loading branch information
vince-styling committed Mar 26, 2016
2 parents 3f5383f + 3c68cbf commit 42e83e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void run() {
if (mResponse.isSuccess()) {
mRequest.deliverSuccess(mResponse.result);
} else {
mRequest.deliverError(mResponse.error);
mRequest.deliverError(mResponse.errorDetail);
}

// If this is an intermediate response, add a marker, otherwise we're done
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/com/duowan/mobile/netroid/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static <T> Response<T> error(NetroidError error) {
public final DiskCache.Entry cacheEntry;

/** Detailed error information if <code>errorCode != OK</code>. */
public final NetroidError error;
public final NetroidError errorDetail;

/** True if this response was a soft-expired one and a second one MAY be coming. */
public boolean intermediate = false;
Expand All @@ -53,18 +53,18 @@ public static <T> Response<T> error(NetroidError error) {
* Returns whether this response is considered successful.
*/
public boolean isSuccess() {
return error == null;
return errorDetail == null;
}

private Response(T result, DiskCache.Entry cacheEntry) {
this.result = result;
this.cacheEntry = cacheEntry;
this.error = null;
this.errorDetail = null;
}

private Response(NetroidError error) {
this.result = null;
this.cacheEntry = null;
this.error = error;
this.errorDetail = error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
* framework's implementation. See the framework SDK documentation for a class
* overview.
*/
public class LruCache<K, V> {
private final LinkedHashMap<K, V> map;
public class LruCache<K, V> {

private final LinkedHashMap<K, V> map;
private static final int DEF_ENTRY_SIZE = 1;

/** Size of this cache in units. Not necessarily the number of elements. */
private int size;
Expand Down Expand Up @@ -242,7 +244,7 @@ private int safeSizeOf(K key, V value) {
* <p>An entry's size must not change while it is in the cache.
*/
protected int sizeOf(K key, V value) {
return 1;
return DEF_ENTRY_SIZE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.duowan.mobile.netroid.stack;

import android.net.http.AndroidHttpClient;

import com.duowan.mobile.netroid.AuthFailureError;
import com.duowan.mobile.netroid.Request;
import com.duowan.mobile.netroid.Request.Method;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
Expand All @@ -36,6 +38,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* An HttpStack that performs request over an {@link HttpClient}.
Expand All @@ -52,16 +55,16 @@ public HttpClientStack(HttpClient client) {
}

private static void addHeaders(HttpUriRequest httpRequest, Map<String, String> headers) {
for (String key : headers.keySet()) {
httpRequest.setHeader(key, headers.get(key));
for (Entry<String, String> header : headers.entrySet()) {
httpRequest.setHeader(header.getKey(), header.getValue());
}
}

@SuppressWarnings("unused")
private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) {
List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size());
for (String key : postParams.keySet()) {
result.add(new BasicNameValuePair(key, postParams.get(key)));
for (Entry<String, String> param : postParams.entrySet()) {
result.add(new BasicNameValuePair(param.getKey(), param.getValue()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.duowan.mobile.netroid.stack;

import android.text.TextUtils;

import com.duowan.mobile.netroid.AuthFailureError;
import com.duowan.mobile.netroid.Request;
import com.duowan.mobile.netroid.Request.Method;

import org.apache.http.*;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHeader;
Expand All @@ -29,6 +31,7 @@

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -68,8 +71,8 @@ public HttpResponse performRequest(Request<?> request) throws IOException, AuthF

URL parsedUrl = new URL(request.getUrl());
HttpURLConnection connection = openConnection(parsedUrl, request);
for (String headerName : map.keySet()) {
connection.addRequestProperty(headerName, map.get(headerName));
for (Entry<String, String> header : map.entrySet()) {
connection.addRequestProperty(header.getKey(), header.getValue());
}

setConnectionParametersForRequest(connection, request);
Expand Down

0 comments on commit 42e83e6

Please sign in to comment.